C++ Linking

C++ Linking with Visual Studio
Static libraries (.lib) can be linked into a DLL without any issues.

DLL's require an import library (also .lib) to use (or possibly some other import specification).

Creating a DLL is done in these steps:


 * Declare exports "dllexport"
 * Compile as DLL, which creates a import .lib for linking with other stuff, and the actual DLL

You can inspect the exported symbols using. To use Visual Studio command line tools, execute: "%vcinstalldir%\bin\vcvars32.bat"

Check for 32-bit/64-bit platform by: dumpbin /headers test.lib | egrep -A3 "File Type"

Which outputs "14C machine (x86)" for 32-bit and "8664 machine (x64)" for 64-bit libraries.

Exporting All Public Symbols
GCC exports all public symbols to a shared library automatically. According to MSDN, Visual Studio or link.exe cannot automatically export symbols, you have to specify them manually, either by prefixing all methods with  or by manually generating a   file.

As of 2010-04-13, I have not been able to find any tool to do this automatically.

C++ Linking on Mac OS X
On Mac OS X, libraries have the following naming standard: libstaticlibrary.a libsharedlibrary.dylib Loading shared libraries is case-insensitive.

If .dylibs cannot be located, use: DYLD_LIBRARY_PATH=/path/to/lib/ ./executable

Creating Shared Library from Static Libraries
g++ -dynamiclib -all_load libinput1.a libinput2.a -o liboutput.dylib is a  inherited by g++ which forces   to include all members of the static archive libraries in the output shared library.

Checking the output: nm liboutput.dylib