开发者

Wrong Library Imported via #pragma comment(lib, ...) in Visual C++

I'm using Visual Studio 2008. I have a DLL and a test program EXE. There is a header file for the DLL that contains this:

#ifdef _DEBUG
    #pragma comment(lib, "FooD.lib")
#else
    #pragma comment(lib, "Foo.lib")
#endif

The intent is to dynamically link to FooD.dll through the FooD.lib import library, for a debug build, and to Foo.dll for a release build. The problem is that when I run the debug-build test program, it wants to be linked开发者_运维知识库 to Foo.dll.

I have verified that _DEBUG is defined for the test program in a debug build. If I replace the #pragma comment with an #error directive, I see the error, so I'm pretty sure that the #pragma comment is being processed as I expect.

I have also verified that both FooD.dll and FooD.lib exist. (Foo.dll and Foo.lib do not exist.) But at runtime, I get a "Cannot find Foo.dll" error message.

Any idea what might be going wrong, or where I can look to figure out why the incorrect DLL is being looked for at runtime?


Found my problem: the Foo.def file had this line:

LIBRARY "Foo.DLL"

This causes the import library to specify Foo.dll, regardless of what the actual DLL name is. So I just commented out that line, and everything worked fine thereafter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜