我在头文件中有以下内容。
namespace silc{
class pattern_token_map
{
/* Contents */
};
pattern_token_map* load_from_file(const char*);
}
在 CPP 文件中(这有适当的包含)
pattern_token_map* load_from_file(const char* filename)
{
// Implementation goes here
}
在另一个 CPP 文件中。这已经得到了所有适当的包括。
void some_method()
{
const char* filename = "sample.xml";
pattern_token_map* map = load_from_file( filename ); // Linker complains about this.
}
我收到一个链接器错误,说未定义对load_from_file
. 我看不到这里出了什么问题。
任何帮助,将不胜感激。
编译器:G++ 操作系统:Ubuntu 9.10
编辑
这是使用的链接器命令。
g++ -L/home/nkn/silc-project/third_party/UnitTest++ -o tests.out src/phonetic_kit/pattern_token_map.o tests/pattern_token_map_tests.o tests/main.o -lUnitTest++
错误来自pattern_token_map_tests.o
,函数在pattern_token_map.o
. 所以我猜链接的顺序并没有造成问题。(我已经从命令中删除了一些文件以简化它)