CRT library: wrong version - c++

During the compilation process of my application (Debug mode), I am getting the following error, related to the CRT library:
16>libcpmt.lib(stdhndlr.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in poStat.obj
According to the Microsoft MSDN topic, I need to set the runtime library to /MTd in order to append the correct library compiled with debug mode. I also have to define a _DEBUG flag - and thats exactly what I have done.
Even though I have did everything it requires to use the CRT with debug mode, its still trying to use one without the debug mode (libcpmt.lib instead of the libcpmtd.lib).
How can I fix this?
Update
When I go to the C:\Program Files\Microsoft Visual Studio 11.0\VC\lib and change the name of libcpmtd.lib to the libcpmt.lib (had to temporary remove the existing libcpmt.lib) it builds successfully in a debug mode.

As Hans Passant already pointed out, the reason you have this is because some of the .lib or .obj files you are linking were compiled with Release settings, and some with Debug. The real question for you now is how to find which libraries or object files need to be fixed. Here is one way to do this
link /dump /all "Path_To_Lib_or_Obj" | findstr /L "\/DEFAULTLIB"
This will print out all default libraries, including CRT. This command has to be executed for each .lib and .obj that appears on your linker build command. For Debug you should see something like:
/DEFAULTLIB:msvcprtd
/DEFAULTLIB:MSVCRTD
/DEFAULTLIB:OLDNAMES
...
and for Release:
/DEFAULTLIB:msvcprt
/DEFAULTLIB:MSVCRT
/DEFAULTLIB:OLDNAMES
...

Related

Need to use release library in cmake debug build

I have generated a release library using CMAKE that needs to be kept proprietary. I plan to put header files into an include directory and library files into a lib directory.
The CMAKE line used to generate the library is:
add_library(Ethernet STATIC ${eth_srcs} $<TARGET_OBJECTS:EthernetBootloader>)
There are separate Visual Studio solutions for generating a library and running a control panel that uses the library. Running the Control Panel in debug mode only works with a debug library. If the Control Panel compiles and runs in debug mode and the library was built in release mode I get several errors that look like:
Ethernet.lib(ethernet.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
Ethernet.lib(ethernet.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in main.obj
I am beginning to write a "ethernet-config.cmake" file that contains:
set(ETHERNET_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/include")
set(ETHERNET_LIBRARIES "${CMAKE_CURRENT_LIST_DIR}/lib/Ethernet.lib")
string(STRIP "${ETHERNET_LIBRARIES}" ETHERNET_LIBRARIES)
and the CMakeLists.txt looks something like:
set(Ethernet_DIR "C:/MotorController/public")
find_package(Ethernet REQUIRED)
include_directories(${ETHERNET_INCLUDE_DIR})
target_link_libraries(ControlPanel ${ETHERNET_LIBRARIES})
How do I use a release library in a Visual Studio 2015 Windows 7 64-bit debug application? I think I need to adapt my CMakeLists.txt for the debug application but haven't figured it out.

mismatch detected for 'vccorlib_lib_should_be_specified_before_msvcrt_lib_to_linker': value '1' doesn't match value '0' in msvcrtd.lib

I have a C library project for UWP. There are some C files which are calling C++ WINRT functions defined in CPP file.It is compiling successfully and generating a library file(LIB). I am compiling in Visual Studio 2015 with update 1 and target platform is 10.0.10240.0
But, I want to generate DLL instead of LIB file. Here's the changes I did to change the project so that it generates DLL instead of LIB.
Try1:
So, In the startup project, In Configuration Properties => General I change Configuration from Static Library to Dynamic Library.
And in all the project, I changed from Multi-threaded Debug(/MTd) to Multi-threaded Debug DLL(/MDd).
Try2:
Created a new project Windows Universal Project and added the all the files from the project creating LIB to this project. Still, I am getting the below errors.
Now, I am getting the errors
vccorlibd.lib(init.obj) : error LNK2038: mismatch detected for 'vccorlib_lib_should_be_specified_before_msvcrt_lib_to_linker': value '1' doesn't match value '0' in msvcrtd.lib(app_appinit.obj)
vccorlibd.lib(init.obj) : error LNK2005: __crtWinrtInitType already defined in msvcrtd.lib(app_appinit.obj)
msvcrtd.lib(initializers.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
Any Suggestions how to resolve this.
I had the same Issue and fixed it using the linker flags:
/nodefaultlib:vccorlib /nodefaultlib:msvcrt vccorlib.lib msvcrt.lib
for debug builds you can use:
/nodefaultlib:vccorlibd /nodefaultlib:msvcrtd vccorlibd.lib msvcrtd.lib
The standard /nodefaultlib did not work for me.
The following linker flags (for debug) did the trick in my case:
/defaultlib:'vccorlibd.lib' /defaultlib:'msvcrtd.lib'

C++.NET, Link can't find file Debug/.obj (notice strange file name)

I have added some information to this question, below the line of xxxx.
I am attempting to move a large ActiveX (legacy) control from Visual C++ version 6 to Visual Studio 2010. The build went just fine under VSC++6. The automated conversion (within VS2010) seemed to run smoothly. There were a number of minor errors which had to be corrected in the code, such as having to declare variables to be integer rather than letting them default. Upon fixing the last error and building, the link step gave this error:
1>LINK : fatal error LNK1104: cannot open file '.\Debug\/.obj'
I have searched and found a couple people had asked about this problem, but the solutions were very project specific. I could find nothing that applied to my situation.
There were two projects in the original solution. To attempt to solve the problem, I separated them into two separate solutions, one of which produces a .dll and works and the other (to produce the activeX component) which fails with the above error.
I really don't know where to look.
I have no .cpp nor .h files with Debug in the filename.
There must be something telling the linker to look for this file... but where? How would I even recognize it. (I'm not even sure what the forward slash in the filename represents. Is it escaping the period... or does the pair of characters (backslash forwardslash, \ /) escape the forward slash meaning it is part of the filename?)
Where do I even start?
I think that I have heard that Visual Studio generates command lines which actually do the compilation and linking. Is there any way to see the generated command line to do the Link?
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I just located 3 files with names and content as shown. They seem to be
related to the problem. The 3rd file shows the bad file name (twice). Can anyone tell me where in the Visual Studio GUI they are set up? Or what may cause the erroneous entries in the last file?
custombuild.command.1.tlog -------------------
^C:\DOCUMENTS AND SETTINGS\USER1\DESKTOP\QUILT00\QGETL32.ASM
..\Assembler\ml /Fo.\Debug\Qgetl32.obj /coff /I. /Zi /c /Cx /Ta Qgetl32.asm
^C:\DOCUMENTS AND SETTINGS\USER1\DESKTOP\QUILT00\ROT32.ASM
..\Assembler\ml /Fo.\Debug\Rot32.obj /coff /I. /Zi /c /Cx /Ta Rot32.asm
custombuild.read.1.tlog ----------------------
^C:\DOCUMENTS AND SETTINGS\USER1\DESKTOP\QUILT00\QGETL32.ASM
^C:\DOCUMENTS AND SETTINGS\USER1\DESKTOP\QUILT00\ROT32.ASM
custombuild.write.1.tlog ---------------------
^C:\DOCUMENTS AND SETTINGS\USER1\DESKTOP\QUILT00\QGETL32.ASM
C:\DOCUMENTS AND SETTINGS\USER1\DESKTOP\QUILT00\DEBUG\.OBJ
^C:\DOCUMENTS AND SETTINGS\USER1\DESKTOP\QUILT00\ROT32.ASM
C:\DOCUMENTS AND SETTINGS\USER1\DESKTOP\QUILT00\DEBUG\.OBJ

How do you run cl.exe from cmd using the same settings as in MSVS?

I have a c++ project in MSVS 2010 Express. I have been planning to write several unit tests to validate this project. Right now they go along the following lines:
#include "header.h" //Header is the header for the source I want to test
void testSomeFunction()
{
//Call function (from external src, prototype in header.h)
//Save output to file
}
int main()
{
testSomeFunction();
return 0;
}
I am creating these source files outside my project because I want to be able to run each of them as individual executable, but I am having trouble getting the Microsoft linker to link them.
This is my problem so far (CMD output):
cl ut_Converter.cpp Converter.obj
ut_Converter.cpp
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xlocale(323) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:ut_Converter.exe
ut_Converter.obj
Converter.obj
Converter.obj : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in ut_Converter.obj
Converter.obj : fatal error LNK1313: pure module detected; cannot link with ijw/native modules
I never really use Microsoft products, I'm familiar with using the GNU tools GCC and make but I have to use the Microsoft tools for this and I have no idea how they work.
Maybe I'm going about building these tests the stupid way but it's the best way I can think of right now.
This is what I want to do:
Compile the source files in my project into object files
Compile my test files into object files
Link the test object file with the appropriate project object files to produce the test executable
How do I go about doing that? (I'm guessing there are some settings I need to set to make everything compatible but I have no idea what they are or how I would go about setting them)
Extra: I know it mentions the debug level but I'd be willing to bet that there will be other incompatible settings. Is there a way to find out what the settings are in the program so I can pass them to cl.exe when I run it?
Edit: When I say command prompt I do mean the one that comes with Visual Studio with all the environment variables setup.
Have you tried going to Programs / Microsoft Visual ... / ... Tools / ... Command Prompt, and running from that dos console window which has the environment variables setup?

Can not find mpirxx.h after building the mpir-2.6.0 library in vc++

I need to use mpir-2.6.0 library with visual c++ 2010. My code is going to be in c++.
I extracted both folders (mpir-2.6.0 and vsyasm-1.2.0-win32). Then, I copied the content of the folder vsyasm-1.2.0-win32 (including vsyasm.exe after renaming it to yasm.exe and placing it in: C:\Program Files\Microsoft Visual Studio 11.0\VC\bin\. Then, I opened the project: mpir.sln which is placed in: \mpir-2.6.0\build.vc10. Then, I changed the Project configuration to: Release.
When I try to build the whole solution, I get a lot of errors such as:
error C1020: unexpected #endif c:\proj\mpir-2.6.0\mpir-2.6.0\mpir.h 4 1 lib_mpir_gc
error C1020: unexpected #endif c:\proj\mpir-2.6.0\mpir-2.6.0\mpir.h 4 1 lib_mpir_gc
error C1020: unexpected #endif c:\proj\mpir-2.6.0\mpir-2.6.0\mpir.h 4 1 lib_mpir_gc
But when I build every library separately, it is successful.
After the build, I went to: \mpir-2.6.0\build.vc10\Win32\Release
and find the files:
mpir.lib
mpirxx.lib
mpir.pdb
mpirxx.pdb
But I can not find the files:
mpir.h
mpirxx.h
Which I need to copy them the visual studio include file.
My main source for these configuration is: http://www.exploringbinary.com/how-to-install-and-run-gmp-on-windows-using-mpir/ (but this was for old versions for the library and the ysam). I do not understand the reasons for these errors. I was able to configure the library with old version. But I need to upgrade as there are improvements in the library and mine is very old one.
The output files are now located in mpir\lib\Win32\Release or mpir\dll\Win32\Release.
The recommended way to build MPIR specifcally for your CPU is to first run mpir_config.py which is located in the build.vc10 directory. mpir_config.py will prompt you with a list of CPU options. Then when you open mpir.sln, you should only compile code for the specific CPU. And then you compile the C++ wrapper (i.e. compile lib_mpir_p3 first, and then lib_mpir_cxx).
Edit: I just noticed another error from your original post. You need to rename the directory "mpir-2.6.0" to "mpir". The directory layout needs to be "<>\mpir\build.vc10"
I had the same problem with MPIR 2.6.0 and VS 2012. What I did to make MPIR work was to build lib_gc and lib_cxx, both with win32 and release mode. Because my c++ application is win32 console, this way it worked perfectly.
Becuase my windows is 64, I thought I had to build 64 versions, but turned out that I was wrong.