C++项目编译和链接缺少库
我正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
测试应用是否正确设置了对库的依赖关系?您是否已将新库所在的目录添加到 Visual Studios 搜索路径中? (工具 -> 选项 -> 项目和解决方案 -> VC++ 目录)。测试应用程序是否在链接器“附加依赖项”选项下列出了库(检查项目属性->链接器->输入->附加依赖项)。或者,如果测试应用程序位于同一解决方案中,则在测试应用程序的“项目依赖项”下,依赖项下是否列出了 lib 项目。
.lib 是 dll 的导入库吗?导入库只是 dll 的前端。它会导致您的 dll/exe 在启动时自动加载 dll,并在退出时删除 dll。它还为 dll 中的所有符号提供静态前端。可能发生的问题包括如果 dll 中的符号未导出,因此未放置在导入库中,从而导致链接器错误。
在 Visual Studio 中,旧版本的 .lib 与测试 exe 位于同一路径。当我的项目中有 .lib 并将其设置为复制到多个项目中所有公共库都存在的某个位置时,有时会发生这种情况。有时我会在测试应用程序的同一解决方案中构建 .libs 项目。其他时候我会在测试应用程序之外构建它。当您在解决方案中构建它时,该库将被复制到与测试可执行文件相同的目录中。在链接过程中,它首先出现在 lib 搜索路径中。
链接器搜索路径上的其他位置是否存在该库的旧副本?此处可能会发生与上面 3 中相同的情况。
如果所有其他方法都失败打开详细链接,如下所示此处。查看 Visual Studio 从何处导入库,看看它是否符合您的期望。
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.
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.
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.
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.
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.
即使其中引用的某些符号(函数/变量)不可用,也会生成静态库。当您尝试构建 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.