Need more explanation on LNK2038 mismatch dectected for '_MSC_VER'

不想你离开。 提交于 2020-01-06 02:22:22

问题


I inherited an old program from a colleague that is no longer with the company. It's an CPLEX optimization we use. It was built in house in C++ using Visual Studio 2005 and CPLEX121. The server where it's located is being decommissioned and we're trying to migrate it to a new server. I'm trying to rebuild the new application in Visual Studio 2013 using CPLEX126 for the optimizations.

Error I get is:

Description:

error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1800' in (project name).obj

File:

ilocplex.lib(ilocplex.obj)

There are quite a few of these mismatches. I'm new to Visual Studio and C++, but I've managed to work through getting the CPLEX links updated, and now this error is happening.

From this forum post: error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj

I've been able to deduce there might be something I can do to the toolset or "recompile my libraries" this seemed to work for some people on the last post, but all I need more specific help on how exactly to do that.

No, it's the object files. What the compiler emits. They appear to be inside the .lib file. You'll need to recompile it. – David Heffernan Oct 24 '13 at 20:40

Hi David, iam new to c++ .Iam basically a c# programmmer. Can you please elaborate the comments – user1654136 Oct 24 '13 at 20:43 2

The compiler is telling you to recompile Projectname1.lib with VS2012. – David Heffernan Oct 24 '13 at 20:48

I have no idea what that means and I don't have enough reputation to comment.

Also,

for each project in your solution make sure that Properties > Config. Properties > General > Platform Toolset is one for all of them, v100 for visual studio 2010, v110 for visual studio 2012 you also may be working on v100 from visual studio 2012

the response is "That worked for me"

My Project's Platform Toolset is "Visual Studio 2013 (v120)". Do I need to add some other toolset? there's no other option in the dropdown.

There is also a block of code in the .cpp file:

// set up Visual Studio version #define _VS2005_ # if _MSC_VER < 1400 # undef _VS2005_ # endif

I also don't know what this is doing to see if it is causing the error.


回答1:


First - you will not be able to recompile the CPLEX library because you will not have the source code and there is no way you are going to get it unless you work in the R&D team inside IBM. So forget that line of reasoning. You are dependent on IBM providing a pre-built library that works with the version of the compiler that you are using.

When you say that you "managed to work through getting the CPLEX links updated, and now this error is happening", I am guessing that you managed to update the paths to the C++ include files that are used by the compiler, so your compilation errors have gone away. But you may not yet have updated the library paths to show the compiler the right sets of libraries to link with.

From the error you are posting, '_MSC_VER': value '1600' doesn't match value '1800', that says to me that you are trying to link with the CPLEX library built for VS2010, while your code was compiled using VS2013. See for example How to Detect if I'm Compiling Code With Visual Studio 2008?

If you are new to C++, it is plain crazy for anyone to expect you to walk into a large existing code base and try to port to new compiler and libs and get it to run straight away without doing a bit more research and background learning. Have you tried to build and run the C++ examples provided with CPLEX?

Have you read the instructions for setting up a C++ project with CPLEX? They are in a file c_cpp.html in the CPLEX folder.

Now, I don't know that CPLEX has libraries for VS2013. I haven't got 12.6 here, so I can't be sure. Have a look in your installed copy of CPLEX, probably something like:

C:\Program Files\IBM\ILOG\CPLEX_Studio126\cplex\lib

...and that should tell you what versions of VS are supported. I have x64_windows_vs2008, x64_windows_vs2010 and x64_windows_vs2012

If there isn't a copy of the library for VS2013, then I think you are going to have to go back to VS2012 or VS2010. There may be a way to configure VS2013 to make it work like VS2012 and trick it onto generating code that is compatible; but I am guessing that would not be a "supported configuration" from IBM's perspective.

The stuff about #define VS2005 is using the C++ pre-processor to define a symbol which can be used to turn on or off bits of your source code. Look for where in your source code that symbol is used. I am guessing that is entirely separate from your linking issue. You might choose to do something similar if you make changes in your code to make it work (or work better) with the newer version of the compiler and libraries.




回答2:


Tim's answer is entirely correct, but here's the piece that he couldn't check...

There doesn't exist CPLEX libraries for VS2013, so you should not spend time looking for some... This can be seen in this report, which you can access for other platforms/versions from the CPLEX Optimization Studio Detailed System Requirements.

This means that you will have to use Visual Studio 2012 compiler. You can still use the Visual Studio 2013 environment: what you have to do is to install both versions and instruct Visual Studio 2013 to use the compiler from version 2012 by changing the Platform Toolset. But all the other libraries that your application uses must then have been compiled by the Visual Studio 2012 compiler. You can't mix and match...



来源:https://stackoverflow.com/questions/23143152/need-more-explanation-on-lnk2038-mismatch-dectected-for-msc-ver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!