Reputation: 14877
I have a Visual Studio 2010 C++ project that links statically to tinyxmlSTL
2.5.5 (tinyxmlSTL.lib) and zlib
1.2.7. (zlibstat.lib). There are 4 builds in total covering both x86 and x64 as well as Debug and Release.
All combinations produce working builds except for Release x64 which gets a bunch of errors like this:
MSVCRT.lib(MSVCR100.dll) : error LNK2005: free already defined in LIBCMT.lib(free.obj)
...and a single warning:
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
If I add /NODEFAULTLIB:MSVCRT
to linker options for the application then I get this:
zlibstat.lib(ioapi.obj) : error LNK2001: unresolved external symbol __imp__ftelli64
zlibstat.lib(ioapi.obj) : error LNK2001: unresolved external symbol __imp__fseeki64
Basically, all the projects (app and two libs) are set to use Multi-threaded (/MT)
option in Release builds and yet x86 builds just fine while x64 suffers from above issues.
Any help or idea is highly appreciated.
Upvotes: 0
Views: 2504
Reputation: 78408
You need to double check your settings for x64. One of the projects is using the /MD
flag rather than /MT
.
As per the MSVC docs, The MSVCRT.lib is invoked by using /MD
.
EDIT :
As per your comments, it sounds like zlib is the likely culprit.
zlib has both a static and dll version, but both of these use the /MD
flag by default, so unless you changed that while building zlib - that's your issue.
To build zlib using /MT
:
If you've not already done so, install CMake
Download and extract zlib to e.g. C:\devel
. The download links are about halfway down the homepage. Currently this provides zlib version 1.2.7.
To work around this CMake bug, add
if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND MSVC)
set_target_properties(zlibstatic PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
endif()
to the end of C:\devel\zlib-1.2.7\CMakeLists.txt
In a VS10 command prompt, cd C:\devel\zlib-1.2.7
cmake -H. -Bbuild -G"Visual Studio 10 Win64"
This gets you a VS sloution C:\devel\zlib-1.2.7\build\zlib.sln which you can open. Change the settings for the "zlibstatic" target to /MT
and /MTd
for Release and Debug respectively.
Building each will yield zlibstatic.lib in a subdirectory of build; either "Release" or "Debug".
Upvotes: 2
Reputation: 3874
I know you say that all your libs are linking with /MT but that error suggests that one of them isn't. Re-check that the correct libs are being linked with the x64 Release build.
Upvotes: 1
Reputation: 1364
In the project properties for ALL projects, check that they all use the same runtime type: either DLL or static
This can be found under Project Properties -> C/C++ -> Code Generation -> Runtime Library. Make sure you have the Release x64 build selected.
The particular value isn't very important (in terms of compile errors) but they should all be the same
Upvotes: 1