How do I build an import library (.lib) AND a DLL in Visual C++?
By selecting 'Class Library' you were accidentally telling it to make a .Net Library using the CLI (managed) extenstion of C++.
Instead, create a Win32 project, and in the Application Settings on the next page, choose 'DLL'.
You can also make an MFC DLL or ATL DLL from those library choices if you want to go that route, but it sounds like you don't.
How to import .lib into .dll?
Unfortunately, the VS linker doesn't have an option equivalent to ld
's --whole-archive
which can be used to include an entire library.
Your best bet is to unpack the library and link in the resulting object files. You can use the librarian (lib
tool) for that. To list all members of the library, use lib /LIST
. Object files have to be extracted one by one, using lib /EXTRACT:member
.
How to generate an import library (LIB-file) from a DLL?
You can generate a DEF file using dumpbin /exports:
echo LIBRARY SQLITE3 > sqlite3.def
echo EXPORTS >> sqlite3.def
for /f "skip=19 tokens=4" %A in ('dumpbin /exports sqlite3.dll') do echo %A >> sqlite3.def
The librarian can use this DEF file to generate the LIB:
lib /def:sqlite3.def /out:sqlite3.lib /machine:x86
All of the filenames (sqlite3.dll
, sqlite3.def
, etc.) should be prepended with full paths.
Class library lib and dll files
You can have a library project or a DLL project. A DLL is good if it will be used by multiple exes. A lib is good if you want it to become part of an exe.
DLL projects generate both a DLL file and a lib file. The import lib file is very small and just contains a jump table so the exe can be compiled.
Linking library (.lib) and (.dll) in visual stucio c++ 2008
You do not need source files for use dll. All you need is .dll file. But in this case you should manually get address of every used function. Example for widows you can find here.
Getting address of every function is not very convenient. So you can use .lib file and header files (.h) (but not sources). In C/C++ Additional directories
you should specify path to header files.
So you can configure your project:
- Linker Additional directories. (.lib folder)
- Additional libraries (.lib file)
- C/C++ Aditional directories. (Library headers path)
Related Topics
How to Assert If a Std::Mutex Is Locked
Linux C++ Error: Undefined Reference to 'Dlopen'
Why Is a NaïVe C++ Matrix Multiplication 100 Times Slower Than Blas
How to Monitor a Folder with All Subfolders and Files Inside
String Conversion with Boost Locale: Different Behaviour on Windows and Linux
Are There Any Way to Link My Program with Wine-Compiled Part
How to Create a Game Loop with Xlib
Why Can't I Add a Qgridlayout to a Qmainwindow
Why Isn't Malloc Filling Up Memory
Determine If Linux or Windows in C++
Is the Order of Iterating Through Std::Map Known (And Guaranteed by the Standard)
Send and Receive a File in Socket Programming in Linux with C/C++ (Gcc/G++)
Is There Any "Standard" Htonl-Like Function for 64 Bits Integers in C++