2016-03-01 141 views
0

我使用Microsoft Visual Studio 2010并使用C++编写。有没有办法将静态链接与STL链接?

我的应用程序应该是轻量级的;因此我使用DDK的msvcrt.lib将我的应用程序与存在于任何Windows中的msvcrt.dll链接起来。这个技巧允许我不使用静态链接(libcmt),也不使用MSVC Redistributables中的DLL;所以减少了我的可执行文件的大小。

但现在我需要在我的应用程序中使用STL。有没有办法只与STL链接一些库?我从DDK拿了libcpmt.lib,并试图与它联系;这是我得到了什么:

1>main.obj : error LNK2001: unresolved external symbol "public: virtual char const * __thiscall std::exception::what(void)const " ([email protected]@[email protected]@UBEPBDXZ) 
1>main.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall std::exception::~exception(void)" ([email protected]@@[email protected]) 
1>main.obj : error LNK2001: unresolved external symbol "public: __thiscall std::exception::exception(char const * const &)" ([email protected]@@[email protected]@Z) 
1>main.obj : error LNK2001: unresolved external symbol "public: __thiscall std::exception::exception(class std::exception const &)" ([email protected]@@[email protected]@@Z) 
1>main.obj : error LNK2001: unresolved external symbol "void __cdecl std::_Xlength_error(char const *)" ([email protected]@@[email protected]) 

如何链接我的libcpmt.lib从DDK应用?链接后将多少字节添加到可执行文件?是否有另一个(第三方)STL轻量级?

+1

只是fyi tst :: exception不是STL的一部分,它是C++标准库的一部分。 – PeterT

+0

我知道;但它在'libcpmt.lib'中,不是吗? – deselect

+1

IIRC MSVC中的STL根本不需要链接。话虽如此,你的应用程序可能比你想象的要沉重得多。你认为'msvcrt便宜?它位于Microsoft不应该依赖的事物的黑名单上。当你触摸它时,你的过程是自动怀疑的。预计Windows会启动它的应用程序兼容性工作,以确保您的过时应用程序仍然运行在现代Windows版本上(现代=本世纪; MSVCRT可以追溯到1998年)。 – MSalters

回答

0

这可能是不可能的,至少不可靠。 C++标准库可能依赖于C标准库的某些功能,但您试图使用的未版本化的msvcrt.dll是非标准的。

相关问题