“多重定义”的错误报告
我一直在用 C++ 开发一个跨平台库。我在 Windows (MinGW/msys) 和 Ubuntu (g++) 中进行编译,并且编译时没有任何错误。
我刚刚接触到了装有 Kubuntu 的计算机。当我尝试在那里编译它时,我收到一些错误,指出我对某些变量有多个定义。这些变量在头文件中定义 extern
并在一个 cpp 中的一行中定义。
./libAoTK.a(aotk_unix.o):/home/rickard/c++/AoTK/src/aotk_unix.cpp:16: multiple definition of `AoTK::disp'
./libAoTK.a(aotk_unix.o):/home/rickard/c++/AoTK/src/aotk_unix.cpp:12: first defined here
aotk_unix.cpp 中的代码只有一个定义disp
,第 12 行和第 16 行没有对 disp
的引用。
我不明白为什么它无法链接,而完全相同的代码在另一台 *nix 机器上可以正常编译。
I have been working on a cross-platform library in C++. I been compiling both in Windows (MinGW/msys) and Ubuntu (g++) and it compiles without any errors.
I just got the hand on a computer with Kubuntu. When I try to compile it there I get some errors saying that I have multiple definitions on some variables. Those variables are defined extern
in a header file and defined in one cpp at one line.
./libAoTK.a(aotk_unix.o):/home/rickard/c++/AoTK/src/aotk_unix.cpp:16: multiple definition of `AoTK::disp'
./libAoTK.a(aotk_unix.o):/home/rickard/c++/AoTK/src/aotk_unix.cpp:12: first defined here
The code in aotk_unix.cpp has only one definition of disp
, and on lines 12 and 16 there are no references to disp
.
I do not understand why it fails to link, while the exact same code compiles fine on another *nix machine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 bdonlans 评论的帮助下弄清楚了。问题出在创建 lib-archive 时的 makefile 中。我使用的命令
不会覆盖存档中的现有文件,当更改为
链接时没有任何错误
I figured it out with the help of bdonlans comment. The problem was in my makefile when creating lib-archive. I used the command
which did not overwrite exist files in the archive, when changing to
it links without any errors