Reputation: 6330
I added a dll project to my solution and explicitly referenced it by an executable project. The executable is complaining that it can't find the lib.
Any ideas how to set the project to create the required lib file? And prehaps why the project would not create one?!?
Cheers
NOTE I have searched the project and the file isn't being created anywhere.
Upvotes: 11
Views: 12415
Reputation:
I've seen this before. And have actually just hit is again recently. A .lib file is not created if nothing is exported. Exporting functions happens two ways.
1) mark a function with __declspec(dllexport).
OR
2) Use a .def file which lists all those functions that are to be exported.
Solution:
1) Usually requires a compile time flag to be set to activate a preprocessor block to set some #define to the __declspec(). Someone else listed that in their post.
2) Requires setting the line Properties->Linker->Input->Module Definition File.
Upvotes: 4
Reputation: 3504
In the Linker -> Advanced property tab of the DLL project, verify that the value for Import Library (the .lib file you are looking for) is correct/reasonable. The value of this property will determine what the import library is named, and where the linker will write it to.
You may also need to generate an imports definition file (.def) in your project, or check your header files and make sure your exported functions are tagged with the __declspec(dllexport) qualifier in the header file. This is usually toggled by a #define such as:
#ifdef MYAPI_EXPORTS
#define MYAPI_API __declspec(dllexport)
#else
#define MYAPI_API __declspec(dllimport)
#endif
void MYAPI_API foo(int bar);
Basically you want the compiler to see dllexport when it is building the library, but dllimport when your client code is #including the header file. If Visual Studio generated the basic project structure, it probably already created a suitable #define to use.
You do not have to both create the .def file and add the dllexport, just one or the other. I prefer the latter. Also, if you choose to use a .def file, you need to specify it in the Linker properties of your library project.
Upvotes: 12
Reputation: 2884
Check the project that builds the DLL. If it isn't producing a .lib, you probably haven't told it to. You can change the output of the project from a DLL to a static library in Properties->General->Configuration Type (choose Static Library .lib)
Upvotes: 1
Reputation: 4783
Did you included the lib file in Project Properties->Linker->Input sheet in Exe Project.
And also make sure you included the Additional references in Linker tab.
Upvotes: 1