Yan*_*ang 17 c++ linker static poco visual-c++
我一直试图使用Visual Studio 2008命令行工具静态链接到Windows上名为Poco的C++库.
我建立我的程序:
cl /I..\poco\lib /c myapp.cpp
link /libpath:..\poco\lib myapp.obj PocoNet.lib
Run Code Online (Sandbox Code Playgroud)
这导致在运行时需要PocoNet.dll和PocoFoundation.dll的exe.
我花了一些时间阅读Windows中的链接,并学习cl /MT
静态链接标准库,同时cl /MD
动态链接.
我试图指明/MT
,但这似乎没有改变任何东西; 我的应用程序仍然需要Poco DLL.(我也怀疑这/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
Run Code Online (Sandbox Code Playgroud)
然后我尝试堆叠更多的标志:
/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
Run Code Online (Sandbox Code Playgroud).lib
完全放弃,如此处所示:与上述相同的错误
我也试过上面的一些组合,都无济于事.
任何线索将不胜感激.但同样有用的是指向调试(或了解)这些类型问题的资源的任何指针.
Ale*_*lex 15
您必须在命令行上定义POCO_STATIC并与PocoFoundationmt和PocoNetmt.lib链接:
C:\ test> cl/MD/WX/nologo/EHsc/DPOCO_STATIC/DUNICODE/D_UNICODE/I..\poco\Foundation•include/ I ..\poco\Net\include/c exp.cpp
exp.cpp
C:\ test> link /lpathpath:..\poco\lib/WX/nologo exp.obj PocoNetmt.lib PocoFoundationmt.lib
[UPDATE]如果使用/ DPOCO_STATIC进行编译,则无需在链接器命令行上指定POCO库.头文件包含#pragma comment(lib,"PocoXXXmt.lib")语句,这些语句应确保链接所有必需的库.
如果不使用/ DPOCO_STATIC进行编译,则会自动链接DLL导入库.[/ UPDATE]
归档时间: |
|
查看次数: |
15743 次 |
最近记录: |