Eclipse-CDT/C++:尽管创建了正确的 .o 文件并将其传递给链接器,但未定义的引用错误

发布于 2024-12-18 04:31:10 字数 743 浏览 3 评论 0原文

首先:我没有使用已经编译的库。

情况是这样的:我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凹づ凸ル 2024-12-25 04:31:10

三种可能性:

1)“未定义”符号实际上不在您的库中

 This is unlikely, but you can verify using the "nm" Linux command

2)您没有在 Eclipse 中正确设置库搜索路径(“dash-big-L”)

Three possibilities:

1) The "undefined" symbols aren't actually in your library

 This is unlikely, but you can verify using the "nm" Linux command

2) You aren't setting the library search path ("dash-big-L") correctly in Eclipse

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文