Alexander
Alexander

Reputation: 20244

Add /MT compile flag to project

I have VisualStudio 2012 and I a trusted third party told me I have to add the /MT compile flag to one C# project, so I can use a library which is not necessarily installed on the target system.

I did not find where/how to set this flag in VS.

Upvotes: 0

Views: 2823

Answers (3)

Luaan
Luaan

Reputation: 63772

C# doesn't have that, as simple as that. That's a (native) C++ option and it selects the runtime C++ library to use. In the case of /MT, it will link the multi-threaded MSVCRT statically.

C# uses .NET. It doesn't use the MSVC++ runtime library.

Why would you want to do that anyway? Did the third-party guy say something about the purpose of doing that? Are you trying to troubleshoot some issues? It sounds like you're trying to get a C# application to run on a system that doesn't have .NET - that's not going to happen.

Upvotes: 1

Hans Passant
Hans Passant

Reputation: 942438

It is a setting that only applies to C or C++ projects. It selects the kind of C runtime library that will be used. There are two basic flavors, /MT vs /MD, multiplied by two for Debug and Release builds, /MTd and /MDd. With /MT, the runtime library will get linked into the EXE program itself. With /MD, the runtime library is in a DLL that can be shared by all modules in the process. /MD is very important when you partition your program into multiple modules, like an EXE and one or more DLLs.

A vendor will tell you to use /MT only when they supplied you with a static link library, a .lib file. And gave you only one flavor of it, in general a very questionable practice that you should not put up with since it gives you many less options to build a program that uses the library. Unstated, but very important, is that he also needs to tell you what version of Visual Studio to use.

The .lib file he gave you is not useable from C# at all. You'll have to link it to C or C++ code that uses the library. To interop with C#, you'd typically want to use C++/CLI to write wrapper classes that give you access to the library functions. But you can't do that, C++/CLI only supports building with /MD. All that's left is creating a DLL that exports the functions with a .def file. You have to use pinvoke in your C# code to call them.

Clearly there's a rather major communication failure. You need to follow up and talk to the vendor to get this straightened out. Pursue this aggressively, getting stuck with a wonky library can be an enormous pita for many years to come, increasingly getting worse as tooling evolves.

Upvotes: 4

foobar
foobar

Reputation: 2941

Not sure about VS 2012 but in 2010 it can be done as below:

Right Click on your Project

-> Select Properties

-> Select Configuration Properties

-> Select C/C++

-> Code Generation

-> In Runtime library Select Multi Threaded /MT option

-> Clean & Build your project

Upvotes: 1

Related Questions