我正在使用静态库创建一个简单的拼写检查程序,因为我希望其他人能够使用拼写检查功能。两个问题区域存在于库源代码和库头中。当我编译库时,这是我得到的错误:
ar -cvq libspellcheck.a checker.o
a - checker.o
g++ -o spell-check main.o meta.o libspellcheck.a
libspellcheck.a(checker.o): In function `check_spelling(char*, char*)':
checker.cpp:(.text+0x0): multiple definition of `check_spelling(char*, char*)'
libspellcheck.a(checker.o):checker.cpp:(.text+0x0): first defined here
collect2: ld returned 1 exit status
make: *** [spellcheck] Error 1checker.cpp代码位于here。头文件(spellcheck.h)位于here。
我想知道是什么导致了上面的错误,因为我不能弄清楚。
发布于 2013-01-07 02:25:06
看起来好像您已经向存档中添加了两次checker.cpp。
请尝试使用以下命令:
ar -cvr libspellcheck.a checker.o使用r而不是q将替换任何同名的现有文件,而不是添加该文件的另一个副本。
或者,只需确保在向其添加任何文件之前删除了该存档,以便它始终是空的。
发布于 2013-01-07 01:32:58
问题似乎是链接了两次checker.cpp -你能添加你的makefile吗(还要确保check_spelling没有在checker.cpp中定义两次,并在构建之前尝试清理中间文件)?
https://stackoverflow.com/questions/14184745
复制相似问题