The codebase I am working with uses pragma comment lib to express the dependencies of code to the library that it needs. Its build is very broken. I made an experiment to try to understand the use of pragma comment lib. It is the simplest library and client of the library that I could produce.
Foo.lib
foo.cpp
void foo() { printf("hello\n"); }
foo.h :
#pragma comment(lib, "foo.lib")
void foo();
FooTest.exe
main.cpp :
#include "foo.h"
void main()
{
foo();
}
I am using Visual Studio 2005 (for compatibility with a big commercial program that only accepts plugins made with this version). The problem is that FooTest.exe does not recompile when foo.lib is updated. I make a change to foo.cpp, save, build. Then build the fooTest.exe solution. The fooTest.exe solution does not seem to understand that its dependency has been changed.
I can get around this problem by adding the linker dependency to FooTest.exe but that defeats the entire point of pragma comment lib.
I have read many posts about pragma comment lib and figure it is working for lots of people. In my overall codebase and my test it is not working. I must be missing something.
Scott
The
comment lib
pragma inserts a linker directive. The linker sees this and adds that library to its list of inputs. That is all it does. What you want is a project dependency, which you seem to know how to configure.Visual Studio 2005 pragma comment documentation