compile incompatibility: "/mt" and "clr"  
Author Message
AcrossThePond





PostPosted: Visual C# General, compile incompatibility: "/mt" and "clr" Top

I am trying to write a C++ wrapper for my Csharp code -- essentially to go from "unmanaged" to "managed" code. I used some samples on the internet as a basis but have hit some issues when compiling in Release mode v. Debug mode....

It works fine in Debug mode!

It fails in Release mode: "D8016" /clr and /mt are incompatible (etc.)

I am using VS2005 and it seems like some things have changed with respect to the "clr" compile switch. It's frustrating because it works when compiled in debug mode. I have tried everything to resolve the compatibility issue, but it seems like VS2005 just overrides the options at run time and forces "/mt" on me (even though I change it to "/md"). "clr" is required and nothing works when I turn that off.

So where do I go from here I'm trying it now in VS2003 but seem to be hitting a different issue: unresolved link... I'll need to look more into that.

Maybe there's another way to do this that is compatible with the newer versions of Visual Studio



Visual C#3  
 
 
RizwanSharp





PostPosted: Visual C# General, compile incompatibility: "/mt" and "clr" Top

Try Searching google for this "compile incompatibility: "/mt" and "clr"" There are a lot of discussions on this Issue. I'm not expert of C++ or Cross language so I cant guide you better. But searchig this on google will really help you.

Best Regadrs,



 
 
AcrossThePond





PostPosted: Visual C# General, compile incompatibility: "/mt" and "clr" Top

Thanks RizwanSharp for taking the time to reply...

I had indeed searched through the internet (Google, etc.) before posting my question, but most of the suggested solutions state that the compiler switches should be changed. Although I make the change in the properties, somehow they seem to be overridden. I may need to try and revert to an earlier version of Visual Studio but the caveat being I know my code has some built-in issues whenever I am forced to upgrade down the road...

Some interesting information I picked up along the way:

http://www.winterdom.com/cppclifaq/archives/000492.html

In Visual C++ 2005, the only supported configuration for managed images is linking them against the DLL version of the CRT (C Runtime Library). This means that if you compile with the /clr switch, you should compile with the /MD in order to link with MSVCRT.LIB (or /MDd for debug versions). Trying to link with /MT to use the multi-threaded static linking version of the CRT (LIBCMT.LIB) is not longer a supported option.
P.S: there are no single-threaded variants of the CRT in VS 2005 anymore, by the way.

http://www.codeproject.com/managedcpp/WhidbeyBreakingChanges.asp

12. Switch conflict: /clr and /MT

Affected User Scenario:
Users will need to replace /MT with /MD for their code targeting .NET

Description:
There is no support in the CRT for statically linking managed
applications.

Customer Workaround:
Customer needs to change /MT to /MD and link dynamically to the CRT.

Rationale:
There is no support in the C Runtime Library to statically link to a managed application. All managed applications have to be dynamically linked; thus the reason to make the two compiler options conflict.


 
 
RizwanSharp





PostPosted: Visual C# General, compile incompatibility: "/mt" and "clr" Top

Sorry, I have no Idea, Never faced this problem. As I told you I dont use unmanaded dll's in my code.

May be some other expert can help you with that.

Best Regards,



 
 
VikasKumar





PostPosted: Visual C# General, compile incompatibility: "/mt" and "clr" Top

Could you share your build log for release build.
 
 
AcrossThePond





PostPosted: Visual C# General, compile incompatibility: "/mt" and "clr" Top

Build Log

 

Build started: Project: CPlusWrapper, Configuration: Release|Win32

 

Command Lines

Creating temporary file "c:\Documents and Settings\thepond\My Documents\Visual Studio 2005\Projects\CPlusWrapper\Release\RSP00000137643248.rsp" with contents
[/O2 /Ob1 /D "WIN32" /D "NDEBUG" /D "_VC80_UPGRADE=0x0700" /D "_WINDLL" /D "_MBCS" /FD /EHa /MT /Yu"stdafx.h" /Fp"Release\Bridge.pch" /Fo"Release\\" /Fd"Release\vc80.pdb" /W3 /c /clr:oldSyntax /TP ".\CPlusWrapper.cpp"]

Creating temporary file "c:\Documents and Settings\thepond\My Documents\Visual Studio 2005\Projects\CPlusWrapper\Release\RSP00000237643248.rsp" with contents
[/O2 /Ob1 /D "WIN32" /D "NDEBUG" /D "_VC80_UPGRADE=0x0700" /D "_WINDLL" /D "_MBCS" /FD /EHa /MT /Yc"stdafx.h" /Fp"Release\Bridge.pch" /Fo"Release\\" /Fd"Release\vc80.pdb" /W3 /c /clr:oldSyntax /TP ".\Stdafx.cpp"]

Output Window

Compiling...
cl : Command line error D8016 : '/MT' and '/clr:oldsyntax' command-line options are incompatible

 
 
VikasKumar





PostPosted: Visual C# General, compile incompatibility: "/mt" and "clr" Top

From the build logs its evident that the compiler is using /MT to build this project.

Are you using any source control, if yes can you make sure that the changes are being saved to the vcproj file. You could try making changes to use /MD, save the solution. Close IDE and re-open the solution and check if the changes are still present.

If yes, try building again. If you still get the error, again check to see if the setting is still /MD or has it changed to /MT.

If the setting has changed to /MT change it back to /MD, save the solution and close IDE.

Now try compiling you project from VS.NET 2005 command prompt using devenev.exe /Build release /Project <project file name>. See if this works.

If you are still not able to compile you project, i would sugest posting a feedback at http://lab.msdn.microsoft.com/productfeedback/default.aspx with a sample repro if possible,