Add /MT compile flag to project

Alexander

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.

Hans Passant

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Add File to Project for Intellisense but do not Compile

From Dev

CMake - compile with /MT instead of /MD

From Dev

-fopenmp flag in compile and link

From Dev

Qt - Visual Studio 2013 Add-in won't compile the project

From Dev

How to add gradle 'compile project' dependencies to published *.pom?

From Dev

Add a compile time only sub-project dependency in sbt

From Dev

Compile R package with `-static` flag

From Dev

Add a flag to bash script

From Dev

Add Header Flag in YiiMailer

From Dev

Makefile add last flag

From Dev

Cannot compile modules unless the --module flag is provided

From Dev

compile c++ code with and without fopenmp flag

From Dev

Cannot compile namespaces when the '--isolatedModules' flag is provided

From Dev

Cannot compile modules unless the '--module' flag is provided

From Dev

How to get Nsight EE to compile with -dc flag?

From Dev

What library needs to be installed for -lz compile flag

From Dev

Cannot compile modules unless the '--module' flag is provided

From Dev

What library needs to be installed for -lz compile flag

From Dev

Compile a Cython project and clean

From Dev

Compile options for alsa project

From Dev

Compile Groovy project with -indy

From Dev

Lein compile project with protocols

From Dev

Not able to compile grails project

From Dev

Compile Groovy project with -indy

From Dev

Compile and run Angular Project?

From Dev

Build a project is the same as "compile"?

From Dev

Eclipse maven jboss project - what do I need to add to the pom.xml so maven can compile?

From Dev

Add flag to each item in list

From Dev

Add flag to existing terminal command