问题
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")
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?
回答1:
I'm not sure I understood your question.
"...was the same thing..." No, it is not the same thing.
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.
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)
来源:https://stackoverflow.com/questions/51671022/unresolved-external-symbol-errors-without-pragma-comment-lib-command