开发者

Visual studio - prevent linking of static library

I am creating a static library in Visual Studio 2010. This library will be statically linked with another of my applications to produce the .exe. The thing is that I want my .exe to be statically linked against C adn C++ library (don't want dependency on msvcp100.dll and msvcr100.dll). But what ever I do I can't get it working.

If I link my static library with static C and C++ libs then I can't compile the .exe - Linker complains about "already defined symbols".

If I link my static library with C and C++ DLL then my .exe ends up having dependency on msvcp100.dll and msvcr100.dll.

How do I tell VS to link my static library with static C and C++ libs only when it's being linked in my .exe?

EDIT

Here are a fre linker errors when both static lib and .exe user /MT (i.e. static linking of runtime library):

1>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)
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: class std::locale::facet * __thiscall std::locale::facet::_Decref(void)" (?_Decref@facet@locale@std@@QAEPAV123@XZ) already defined in re2_release.lib(regexp.obj)
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "protected: virtual class std::basic_streambuf<char,struct std::char_traits<char> > * __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::setbuf(char *,__int6开发者_运维问答4)" (?setbuf@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAEPAV12@PAD_J@Z) already defined in re2_release.lib(regexp.obj)
1>msvcrt.lib(MSVCR100.dll) : error LNK2005: _strtoul already defined in LIBCMT.lib(strtol.obj)
1>LIBCMT.lib(crt0init.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library

If I set /NODEFAULTLIB:LIBCMT then errors from mscvrt.lib disappear, but msvcprt.lib errors remain.


I had this problem, and libriks solution solved it. I will quote him here for those who skips reading the comments:

Some module is not using static linking of the runtime library, because your linker errors >show "msvcrt.lib" which is the import library for the DLL version. Look more carefully >through your project settings, and any other libraries you link to, making sure EVERYTHING is >using /MT.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜