开发者

VS 2010 application requires VS runtime installation - how to avoid this?

I have written an application in VS C++ 2010 Express Edition which consists of some DLLs and also depends on some third party DLLs. The application itself is a DLL.

As it turned out, to make it work on another machine, user has to install VS 2010 redistributable runtime.

I tried to build my DLL with flag /MT instead of /MD - I believe this means that I want static linking.. However, in this case I got 'multiple definition' errors ab开发者_运维问答out MSCVRT.lib. Error message also suggested to use flag /NODEFAULTLIB:msvcrt.lib to avoid this. However, with these settings my application still requires runtime installation.

Could somebody please explain me how to avoid this?

Thanks, Robusta

Update: if I simply use /MT flag instead of /MD I get the following error

MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj) MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj) Creating library C:\MyApp\Release\MyApp.lib and object C:\MyApp\Release\MyApp.exp LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library C:\MyApp\Release\MyApp.dll : fatal error LNK1169: one or more multiply defined symbols found

after adding flag /NODEFAULTLIB:library I get no errors, application is built successfully, but still requires runtime installation.

Is it possible that 3rd party libraries, which I also link, require runtime?


You are linking in some code that is still compiled with /MD, possibly some kind of static library. Mixing and matching doesn't work.

Using /MT when you use DLLs is very dangerous. You'll get in trouble when the exported functions return a pointer or a C++ object that needs to be released by the client code. Returning an std::string for example. With /MT, the client will use its own heap allocator to release the memory. Cannot work, the DLL used another heap. You'll leak, very hard to diagnose. Using 3rd party DLLs that were built with a different version of the CRT is a problem for the same reason. There's more details in this MSDN Library article.

Deploying the required CRT DLLs is pretty simple with this download.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜