views:

812

answers:

4

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.

+1  A: 

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.

Vinay
I did :(but because it's not being created this is a mute point?
Adam Naylor
Whether compiler is throwing any error while building lib file?Check the $(OutDir)\$(ProjectName) location for lib
Vinay
There are no errors being thrown (other then the one complaining that the lib file doesnt exist) and the lib doesnt exist any where in the project.
Adam Naylor
+2  A: 

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.

Jeremy
The value is set to $(TargetDir)$(TargetName).libwhich is the same value of other dlls i have in the project which do work.
Adam Naylor
That is really strange, can you add the command line switch manually (in the Command Line property sheet) to specify the import library? Such as /IMPLIB:C:\MyDll.lib?
Jeremy
I added that switch to both the linker command line and the compiler command line and the specified file hasnt been created... it's just refusing to create a lib!?!
Adam Naylor
This *is* an unmanaged C/C++ project, right? Not managed .NET code? :)
Jeremy
is not .net :) but i will check it's not a managed c++ thing...
Adam Naylor
Did not want to be insulting, but though maybe you accidentally had a C++/CLI project, which does not generate a .lib file.
Jeremy
No problem, i'm glad for the help! :)
Adam Naylor
Nope it doesn't appear to have anything relating to managed code...
Adam Naylor
Added more to my answer.
Jeremy
Thanks, there was indeed a problem with my exports!
Adam Naylor
+1  A: 

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)

Matt Jordan
You're assuming a can/want to change the project type.My understanding is that dll's (that aren't dynamically linked) HAVE to create libs. Else they are useless?
Adam Naylor
If that's the case, then your properties are still wrong. You need to check where your .lib file is going. If that's all the problem is, then check Properties->Linker->Import Library, and see where you're creating your lib file.
Matt Jordan
its set to $(TargetDir)$(TargetName).libWhich is the same setting as other dlls in the solution that work fine.
Adam Naylor
Then do a simple debugging step - set it to a known path, like .\Test.lib. That will tell you if its just a path problem.
Matt Jordan
A: 

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.