我一直在尝试使用Visual Studio 2008命令行工具,在Windows上静态链接一个名为Poco的C++库。
我使用以下命令构建我的程序:
cl /I..\poco\lib /c myapp.cpp
link /libpath:..\poco\lib myapp.obj PocoNet.lib
这导致生成的exe在运行时需要PocoNet.dll和PocoFoundation.dll。
我花了一些时间阅读有关Windows链接的内容,并了解到cl /MT
会静态链接标准库,而cl /MD
则动态链接。
我尝试指定/MT
,但似乎并没有什么改变;我的应用仍然需要Poco DLLs。(我也怀疑/MT
是默认行为。)
在..\poco\lib
下查找,我发现还有一个PocoNetmt.lib,但是使用它代替PocoNet.lib会导致大量的LNK2005错误(“已经定义”):
msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in exp.obj
然后我尝试添加更多的标志:
/verbose:lib
: 用于查看正在发生的事情/Zl
: 和之前的结果相同/nodefaultlib:libcmt.lib /nodefaultlib:msvcprt.lib
: 出现了以下错误:PocoFoundationmt.lib(Exception.obj) : warning LNK4217: locally defined symbol ??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)) imported in function __ehhandler$??0Exception@Poco@@QAE@ABV01@@Z
尝试完全不包含
.lib
,就像这里建议的那样: 仍然出现与上述相同的错误
我还尝试了一些组合,但都没有成功。
任何线索都将非常感激。但同样有用的是指向对调试(或学习)此类问题有用的资源的指针。