C++项目编译和链接缺少库

发布于 2024-11-01 14:47:50 字数 241 浏览 0 评论 0原文

我正在 Visual Studio 2010 中构建一个名为 ITPP 的开源 C++ 库。它构建成功,因此我尝试构建它附带的测试程序来尝试它。我在测试程序中收到链接错误,说我构建的第一个库存在一些链接错误,因为它找不到某些函数。

我想我知道缺少什么库,但好像 VS 并不关心。

当我直接构建库时,它链接正确,但当我尝试在某个地方使用它时,IDE 说我构建的库有链接错误,可能的原因是什么?

谢谢,

米杰

I'm building an open source C++ library called ITPP in Visual Studio 2010. It builds successfully and so I try to build the test program that comes with it in order to try it. I get linking errors in the test program saying that the first library I built has some linking errors in that it can't find some functions.

I think I know what library is missing, but it's like VS doesn't care.

What are the possible reasons that when I build the library straight up it links correctly but when I try to use it somewhere the IDE says that the lib I built has linking errors?

Thanks,

mj

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

高速公鹿 2024-11-08 14:47:50
  1. 测试应用是否正确设置了对库的依赖关系?您是否已将新库所在的目录添加到 Visual Studios 搜索路径中? (工具 -> 选项 -> 项目和解决方案 -> VC++ 目录)。测试应用程序是否在链接器“附加依赖项”选项下列出了库(检查项目属性->链接器->输入->附加依赖项)。或者,如果测试应用程序位于同一解决方案中,则在测试应用程序的“项目依赖项”下,依赖项下是否列出了 lib 项目。

  2. .lib 是 dll 的导入库吗?导入库只是 dll 的前端。它会导致您的 dll/exe 在启动时自动加载 dll,并在退出时删除 dll。它还为 dll 中的所有符号提供静态前端。可能发生的问题包括如果 dll 中的符号未导出,因此未放置在导入库中,从而导致链接器错误。

  3. 在 Visual Studio 中,旧版本的 .lib 与测试 exe 位于同一路径。当我的项目中有 .lib 并将其设置为复制到多个项目中所有公共库都存在的某个位置时,有时会发生这种情况。有时我会在测试应用程序的同一解决方案中构建 .libs 项目。其他时候我会在测试应用程序之外构建它。当您在解决方案中构建它时,该库将被复制到与测试可执行文件相同的目录中。在链接过程中,它首先出现在 lib 搜索路径中。

  4. 链接器搜索路径上的其他位置是否存在该库的旧副本?此处可能会发生与上面 3 中相同的情况。

  5. 如果所有其他方法都失败打开详细链接,如下所示此处。查看 Visual Studio 从何处导入库,看看它是否符合您的期望。

  1. Has the test app setup the dependency on the lib correctly? Have you added the directory your new lib is in to Visual Studios search path? (Tools->Options->Projects and Solutions->VC++ Directories). Does the test app list the lib under the linker "additional dependencies" option (check project properties->linker->input->Additional Dependencies). Or alternatively, if the test app is in the same solution, under "Project dependencies" in the test app, is the lib project listed under dependencies.

  2. Is the .lib an import lib to a dll? An import lib is simply a front-end to a dll. It causes your dll/exe to automatically load the dll at startup, and take the dll down on exit. It also provides a static front end to all the symbols in the dll. Problems that can happen include if a symbol in the dll wasn't exported, and therefore wasn't placed in the import lib, causing linker errors.

  3. In visual studio, is an older version of the .lib sitting in the same path as your test exe. This will happen to me sometimes when the I've got the .lib in my project and I've set it to copy to some location where all my common libraries exist across multiple projects. Sometimes I'll build the .libs project in the same solution in the test app. Other times I'll build it outside the test app. When you build it in the solution, the lib gets copied to the same directory as your test executable. This comes first in the lib search path during linking.

  4. Is there an older copy of the lib somewhere else on the linker's search path? Same things can happen here as in 3 above.

  5. If all else fails turn on verbose linking as indicated here. See where visual studio is importing the lib from, see if it matches your expectations.

猫瑾少女 2024-11-08 14:47:50

即使其中引用的某些符号(函数/变量)不可用,也会生成静态库。当您尝试构建 DLL 或 EXE 时,那么所有引用的符号都必须可用 - 因此您收到的错误表明这些符号确实丢失,并且您的库和任何其他库/源都没有提供了它。

A static library will be produced even if some symbols (functions/variables) referenced in it are not available. When you try to build a DLL or an EXE, then all referenced symbols must be available - so the errors you get indicate that these symbols are indeed missing, and that neither your library nor any other library/source provided it.

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