2010-11-09 19 views
1

我正在处理一个(C++)程序,它必须处理大量与文件/目录相关的信息(或多或少我有一个路径作为关键字)。目前我已经尝试使用哈希表实现。考虑到数据量,这看起来工作得很好,但在分析后我发现它们仍然是系统中最慢的一个环节,所以为了改进,我研究了使用Trie。链接错误,尽管一切都存在

我发现以下(C实现)http://linux.thai.net/~thep/datrie/datrie.html并阅读文档,它似乎是一个相当不错的。然而,在试图编写一个简单的测试片段时,我最终会遇到一个奇怪的链接错误。

奇怪的是:有问题的函数存在(如在其中,在cpp文件中)并且创建了对象文件,那么为什么会出现链接错误?

我的代码:

#include <iostream> 
#include <datrie/trie.h> 

extern int main(int, char**) 
{ 
    // create character map covering unicode characters 
    AlphaMap *map = alpha_map_new(); 
    AlphaChar start = 32, end = 1114111; 
    alpha_map_add_range(map, start, end); 
    // create a trie and test it 
    Trie *test = trie_new(map); 
    const AlphaChar key[] = {0x64,0x64,0x64,0x64}; 
    trie_store(test, key, 3); 
    TrieData *data; 
    trie_retrieve(test, key, data); 
    std::cout << *data << std::endl; 
    return 0; 
} 

错误(简体和行包好可读性)

main.obj : error LNK2001: unresolved external symbol 
"int __cdecl alpha_map_add_range(struct _AlphaMap *,unsigned int,unsigned int)" 

main.obj : error LNK2001: unresolved external symbol 
"struct _AlphaMap * __cdecl alpha_map_new(void)" 

使用Visual Studio 2010

回答

2

你在混合C和C++。当你在你的C++代码中包含datatrie/trie.h时,编译器会认为它是一个C++头文件,但libdatatrie是一个C库,它的头文件不会C++友好。

包括像头:

extern "C" { 
#include <datrie/trie.h> 
} 
+0

啊,IC。谢谢!现在工作。 – srcspider 2010-11-09 00:40:07

0

有几个可能性,但你的例子别给我们足够的信息。

  1. 您可能没有将所有的目标文件链接在一起。

  2. 您可能正在编译一个文件,期望一个C++名称 - 损坏的合作伙伴,另一个文件没有。因此,main.o正在寻找重名的名称和导出它的对象正在导出一个未加密的名称,反之亦然。

相关问题