Using Visual Studio C++ 2008 Express:
I am trying to perform the final link step in a build compiled as follows:
-
A library
foo.libis statically compiled (the build does not produce a.dll) with the/MDswitch. The build forfoo.libsucceeds. The.libfile and headers are shipped to a directory where the project for the below library can find them.foo.libsources are written in unmanaged C++. -
A library
bar.dllis compiled as a dynamic library with the/MD /LDswitches.bar.dlldepends onfoo.libexported symbols. Bothbar.dllandfoo.libare built form source using the samecl.exeandlink.exebinaries from the VS2008 Express toolchain.bar.dllsources are written in unmanaged C++. -
All the
.objfiles ofbar.dllbuild successfully, but during the final execution oflink.exethat would producebar.dll, I receive thousands ofLNK2001errors about undefined externals. All of the undefined externals are things that I would expect to be in a standard C++ library: things likestd::basic_stringconstructors, thestd::_Throwclass,ostreamoverloaded operators, and on and on.link.exesays that the undefined externals are undefined withinfoo.lib! -
The goal is for
bar.dllto contain the entire statically linked code offoo.libwithin it, as well as its own objects, but dynamically depend on the existence/resolution ofMSVCR90.dllandMSVCP90.dllat runtime.
Am I trying to set up an impossible situation with this build, or am I just doing something wrong? If this can’t work at all in theory, let me know. Otherwise, please let me know what diagnostics I could try to determine why the C++ library symbols are not available to foo.lib during the final link step.
Edit: More specific information: foo.lib is LLVM 3.1 and bar.dll is the libgl-gdi (llvmpipe) build of Mesa from the master branch (the goal is to produce opengl32.dll that runs on llvmpipe). I have satisfied all the build dependencies as follows:
- LLVM build depends on CMake as the build system, and Python 2.7.
- Mesa build depends on SCons as the build system, LLVM 2.6 or later, Python 2.7, pywin32, python-libxml2, bison, and flex. Out of the above, only LLVM gets shipped around at runtime; the rest are just “tools” used during the build process.
I have also customized the build for each project as appropriate to set environment variables and ensure that they are consistently using only the /MD switch and not /MT or some other switch for selecting a wrong C runtime library.
From the MSDN help:
More specifically – this excerpt: “Applications compiled with this option are statically linked to MSVCRT.lib“
In other words – you need to link your foo.lib to msvcrt.lib.