0

I generated a *.dll with VC++. When I want to use it, a *.lib is required. But I cannot find it. How to get the *.lib? Thanks.

user1899020
  • 13,167
  • 21
  • 79
  • 154
  • 1
    This is old, but might still be relevant (also includes further links): http://stackoverflow.com/questions/584041/how-do-i-build-an-import-library-lib-and-a-dll-in-visual-c – NPE Apr 12 '13 at 15:18
  • I believe it is normally placed in the $(OutDir) of the project (the output directory, which is typically a folder `debug` or `release` off the project folder. You can change this is the Project/Linker settings, if desired. Its been awhile since I used the default, as I always specify where mine are put, so you should check this. Edit: checked the default from MS: "The default name is formed from the base name of the main output file and the extension .lib." – WhozCraig Apr 12 '13 at 15:21

3 Answers3

10

Unless you specify otherwise, the .lib will be generated in the same directory as the .DLL.

If you're getting a dll but not a lib, chances are pretty good that somehow or other you're not actually exporting anything from the dll. In such a case, the linker will create the dll, but won't automatically create a matching import library.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
  • +1 for noting the nullifying creation on no exported symbols (which is also [in the documentation](http://msdn.microsoft.com/en-us/library/67wc07b9.aspx) in case anyone is interested. See the second "Remarks" section). – WhozCraig Apr 12 '13 at 15:27
2

This really depends on your project settings.

Take a look at *.vcprojx

and search for similar pattern:

<link>
<ImportLibrary>.\Release/yourlibrary.lib</ImportLibrary>
</link>
rkosegi
  • 14,165
  • 5
  • 50
  • 83
1

Usually, Visual Studio puts the .lib right next to the .dll file. YOur case sounds like it wouldn't generate a .lib at all. When building libraries as dll, if you want to link to that library in another project (as opposed to using dllopen and the likes), you have to specify which functions should be exported to a lib. For this, you have to prepend all classes or functions you want to export with a __declspec(dllexport) when building the library, and __declspec(dllimport) when linking it.

What you often find is some macro like this:

#ifdef WIN32
    #ifdef MYLIB_EXPORTS
        #define MYLIBAPI __declspec(dllexport)
    #else
        #define MYLIBAPI __declspec(dllimport)
    #endif
#else
    #define MYLIBAPI
#endif

Then, when building the lib, you define the MYLIB_EXPORTS preprocessor, so that it exports, while linking against it imports. Your own Code could then look like this

class MYLIBAPI MyClass
{
public: 
    void SomeFunction()
}
MYLIBAPI void SomeGlobalFunction();

Now, MyClass and SomeGLobalFunction are exported when building, and occur in the lib file.

Dominik
  • 11
  • 2