Eclipse-CDT/C++:尽管创建了正确的 .o 文件并将其传递给链接器,但未定义的引用错误
首先:我没有使用已经编译的库。
情况是这样的:我在 eclipse CDT 中有一个 C++ 项目,其文件夹结构如下:
project
somefoldername
src
include
library
src
include
somefoldername/src 和library/src 被定义为源文件夹,somefoldername/include 以及library/include 被定义为包含文件夹(在 C/C++ 常规 -> 路径和符号下,这也会影响编译器 -I 选项)。
“library”文件夹包含我自己的代码使用的库的源代码(可以在“somefolder”中找到)。嗯,整个项目的编译工作正常,但链接崩溃,库源代码中出现一大堆“未定义的引用”错误。
尽管创建了可以在其中找到缺失函数的 *.o 文件,并且随后也将其传递给链接器,但仍会发生未定义的引用错误。
我做错了什么?
编辑:更新到当前配置并尝试解决问题。
编辑2:接受的答案对我有所帮助,但最大的问题似乎是“立即链接所有内容”策略,然后是日食。我转到 autoconf 并首先构建了库,然后将其链接到主应用程序。虽然这需要更多工作,但这是一种更干净的方法。
At first: I am not using an already compiled library.
Here's the situation: I've got a C++ project in eclipse CDT that has a folder structure like this:
project
somefoldername
src
include
library
src
include
somefoldername/src and library/src are defined as source folders and somefoldername/include as well as library/include are defined as include folders (under C/C++ General->Paths and Symbols, which also affects the compilers -I option).
The "library" folder contains the source code of a library used by my own code (which can be found in "somefolder"). Well, compiling of the whole project works fine, but linking crashes with a whole bunch of "undefined reference" errors in the library's source.
The undefined reference errors occur, although *.o-files are created in which the missing functions should be found - and also are passed to the linker afterwards.
What am I doing wrong?
Edit: Updated to current configuration and the attempts to solve the problem.
Edit2: The accepted answer helped me out a bit, but the biggest problem seemed to be the "linking everything at once"-policy followed by eclipse. I went to autoconf and built the library first, before linking it to the main application. Although it's more work, it's a cleaner approach.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
三种可能性:
1)“未定义”符号实际上不在您的库中
2)您没有在 Eclipse 中正确设置库搜索路径(“dash-big-L”)
在 eclipse cdt 中链接静态库
...或...
3) 也许您使用“C”链接构建了库,但您的程序正在使用 C++ 链接(反之亦然)。如果您使用的是“C”(gcc)编译器,或者有任何“*.c”源文件,请确保所有函数在您的.h标头中都有原型,并且所有原型都使用“extern“C””酌情:
& http://msdn.microsoft.com/ en-us/library/0603949d%28v=vs.80%29.aspx
Three possibilities:
1) The "undefined" symbols aren't actually in your library
2) You aren't setting the library search path ("dash-big-L") correctly in Eclipse
link static lib in eclipse cdt
... or ...
3) Perhaps you built the library with "C" linkage, but your program is using C++ linkage (or vice versa). If you're using the "C" (gcc") compiler, or have any "*.c" source files, then make sure all functions have prototypes in your .h header, and all prototypes use "extern "C"" as appropriate:
& http://msdn.microsoft.com/en-us/library/0603949d%28v=vs.80%29.aspx