Visual Studio 2008 C++. Problem Referencing DLL Project
I've got a solution with two projects in it: one is 开发者_运维知识库a simple dll with a simple class (dll_test). The second project references the dll project and is supposed to be used to test the dll project (dll_tester). The dll project builds fine, but the tester project always complains about not being able to find dll_test.lib instead of dll_test.dll like it's supposed to.
Again, this is with Visual Studio 2008 on a Windows 7 machine. I don't think it makes a difference, but I started the solution with the dll_test project and added the dll_tester project later.
Does anybody know how to resolve this?
Ah, the joys of DLLs and dependencies in Visual Studio. I swear, C# coders have it easy :)
Are you certain that the LIB file is actually created? If your DLL project does not export any symbols you won't get a lib file, and ergo you won't have anything to link to. So you need to make sure that:
Your DLL Project defines something like
MYPROJECTNAME_EXPORTS
. Visual Studio defines this symbol for you when you check the appropriate box when creating the project. If you did not do this, it's quite simple. Ensure that the aforementioned symbol is in the preprocessor directives for your DLL, and in a common header file ensure that the following is defined:#if defined(MYPROJECTNAME_EXPORTS) #define MYPROJECT_API __declspec(dllexport) #else #define MYPROJECT_API __declspec(dllimport) #endif
Once we know that that
MYPROJECT_API
is appropriately defined, we need to make sure that any class or function that we wish to export, has that in it's declarations:class MYPROJECT_API SomeClass { }; // eo class SomeClass
And that class needs to be implemented and actually do something that the compiler has not optimized away.
In short, the reason you cannot find a .lib
file is because none was generated because no symbols were exported from it.
right click the dll_tester in solution explorer and look "Project dependencies..." and make sure that the dll project is checked
精彩评论