问题描述
我在VS2008解决方案中添加了一个项目,并通过项目设置"窗口在启动项目中对该新添加的项目设置了依赖项.问题是我到处都有unresolved external symbol
错误,但是一旦我使用库的功能在文件内写了#pragma comment (lib, "path_to/my_lib.lib")
行,一切就很好了.具体来说,我在包含之后立即添加了该行
I added a project to my VS2008 solution and set a dependency to this newly added project in my startup project via the project settings window. The problem was that I had unresolved external symbol
errors all over the place, but once I wrote the line #pragma comment (lib, "path_to/my_lib.lib")
inside the file using the functions of my library, everything worked just fine. Specifically, I added that line right after my include
#include "path_to/my_lib.h"
#pragma comment (lib, "path_to/my_lib.lib")
我读到要在项目设置窗口中设置依赖项,并写#pragma comment (lib, "path_to/my_lib.lib")
行是同一回事.为什么我没有所有未解决的外部符号错误,而没有在代码中写出该特定行呢?是因为它正在VS2008选项的VC ++目录中给定的另一个文件夹中寻找这种依赖关系吗?
I read that to set the dependencies in the project settings window and writing the line #pragma comment (lib, "path_to/my_lib.lib")
was the same thing. Why did I have all the unresolved external symbol errors without that specific line written in the code? Is it because it's looking for this dependency in a different folder given in the VC++ Directories in the VS2008 options?
推荐答案
我不确定我是否理解您的问题.
I'm not sure I understood your question.
"...是同一件事..." 不,不是同一件事.
项目依赖项 如果所选项目P0依赖于项目DLL1,但不依赖于项目DLL3,则IDE将在P0之前更新(构建)DLL1.参见下面的第一张图片.
Project Dependencies If your selected project, P0, depends on project DLL1 but does not depend on project DLL3, the IDE is updating (buidling) DLL1 before P0. See the first picture, below.
链接器依赖项(链接到库) 使用#pragam comment(lib...
或转到项目的设置以选择库.这些库不一定属于您的解决方案.参见下面的第二张图片.
Linker Dependencies (link to a library) Use #pragam comment(lib...
or go to project's settings to select the libraries. The libraries do not necessary belong to your solution. See the second picture, below.
例如,错误的项目依存关系可能会产生链接错误:
Wrong project dependencies may generate link errors if, for instance:
- 该库是您解决方案的一部分
- 您修改了库的界面(例如,更改了功能签名)
- 您修改项目以适合新界面(以新签名调用函数)
- 您的项目依赖项未未设置为首先构建(更新)库项目;因此它尝试链接到旧库(旧功能签名)
- the library is part of your solution
- you modified the library's interface (changed a function signature, for instance)
- you modify the project to fit the new interface (call the function with its new signature)
- the dependencies of your project are not set to first build (update) the library project; therefore it tries to link to the old library (old function signature)
这篇关于没有#pragma comment lib命令,无法解决的外部符号错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!