error C1190: managed targeted code requires a '/clr' option - c++

Found a lot on this error already, but my case does not get matched with any yet.
I am building a solution (having many projects) in debug mode, and one of them is throwing this error, I am using VS2010 and language is C++, .net version 4.0, earlier this project was compiled in vs2008 and then VS2010, and it was all ok, now I got a new machine which has just VS2010 installed and now facing this error.
Main thing to notice is:
Properties settings:
Project Configuration->General->/CLR is chosen
In C++->General-> No CLR support
I am having these settings since past, it's running all fine in my old machine in VS2010 only in the same debug mode.
What to do?

I am using Visual Studio 2013.
I had similar symptoms for a very simple C program. In the project properties I changed the General / Platform-Toolset setting from "Visual Studio 2010" to "Visual Studio 2013 v120" and that got rid of this error for me.

As the error indicates, precompiled headers are not compatible with /clr-compiled files.
You can disable precompiled headers for the cpp files that are compiled with /clr or for the whole project (C/C++ -> Precompiled Headers -> Precompiled Header : Not Using Precompiled Headers). I'm not sure what the difference is but both seem to work for me.

Doc is not exactly wrong, but I'm betting that's not what's going on here.
Do you by any chance have something like THIS:
#using namespace boost::asio;
...instead of something like THIS?
using namespace boost::asio;
Both "using" and "#using" have valid roles in Visual Studio-- but if you mean the pure C++ language keyword, be sure you are using the former! The latter is indeed used for managed code. See here:
https://msdn.microsoft.com/en-us/library/yab9swk4.aspx
Getting this wrong in Visual Studio 2015 has the following effects:
BUILD OUTPUT:
1>thingy.cpp(3): error C2006: '#using': expected a filename, found 'namespace'
1>thingy.cpp(3): fatal error C1190: managed targeted code requires a '/clr' option
Note that attempting to "satisfy" this in a fit of 4:00 AM frustration by removing the "namespace" keyword and quoting the value will result in only the second error.
(I think that's worth mentioning, because as both Visual Studio and the C++ language specification continue to change, people try all kinds of syntax that they know shouldn't work, and if it suddenly compiles, just assume the spec or the tools have changed in some way they haven't had time to keep up with-- especially if the error messages seem to have something to do with "features" they couldn't care less about, and don't use.)

Related

Visual Studio IntelliSense threat not nested namespace as syntax error

When I decided to switch from CLion to VS22, I found that the code analyzer swears at the new way of writing namespace, that avoid their nesting. I do not know how to make Visual Studio stop considering this an error, as a compiler I used clang and CMake to build, C++ standard is 23
Just for this issue, I suggest you don't use Clang and Cmake, create new project with MSVC and this problem will not occur.
Result:

Getting error D8045 "cannot compile C file <file> with /clr option" even after turning off CLR option

This is in Visual Studio 2015.
I have a native C library that I'm using from my .NET Visual C++ code. I'm aware that I have to change the "Common Language Runtime Support" option to "No Common Language Runtime Support" on the property page for each .c file, per this question. However, even after I have turned that option off, I am still receiving error D8045 when I attempt to compile those files.
Is this a known issue in VS2015, or am I missing something?
It cleared up on its own eventually. I had restarted Visual Studio a few times and it kept happening, which is why I asked this question. I guess some cache somewhere wasn't being updated or got corrupt or something.

Need more explanation on LNK2038 mismatch dectected for '_MSC_VER'

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.
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.
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...

VS 2010 intellisense not working for upconverted project

We have a very big C++ solution with several projects for which intellisense works perfectly in Visual Studio 2008, but not at all in Visual Studio 2010 (not even for structs defined in the same file where they are used). I've verified that intellisense does work in VS 2010 for other projects on my machine. I've tried importing one of the problematic projects from a brand-new solution with no success. Re-building the project files from scratch seems promising, but it would require days of work to follow that path, with no guarantee of success at the end. Any alternative suggestions are welcome. The actual error message I get is:
"Intellisense: 'No additional information available'(See 'Troubleshooting IntelliSense in C++ Projects' for further help.)
I've tried that, but there's basically only one suggestion on the MSDN webpage, to make sure "stdafx.h" on the include path, but we're not using precompiled headers and don't include it from anywhere, so I'm pretty sure that's not the problem.
Have you deleted all of the generated database (.ncb and .sdf) files? Corrupted database files is the most likely cause of Visual Studio failing to display IntelliSense.
Intellisense was not included as a component of Visual Studio 2010 for C++/CLI. Unfortunately, it seems they are not going to support it soon either. This is an incredible detriment, as i find myself having to open VS2005 on occasion to simply find an object member.
Here is Microsoft's release on the subject:
http://blogs.msdn.com/b/vcblog/archive/2011/03/03/10136696.aspx

ZLib.lib(d000062.o) : warning LNK4078: multiple '.text' sections found with different attributes

I downloaded zlib from their website and I have the link warning from the title. I also compiled zlib and still have same warning. Do you know how may I fix this? I don't like warning of any kind in my projects:)
I use Visual Studio 2010.
Apparently the compiler used to generate the .lib import for the DLL isn't entirely compatible with Visual Studio:
I thought MinGW can be a one-stop shop
that'll do what's needed, and we won't
need anymore the awkward two-tool
combination that we used to use around
zlib-1.2.3. It seems we need another,
even more awkward two-tool combination
now.
Cosmin Truta built a new version using Visual studio. It should fix the warnings.