How to statically link using link.exe

本小妞迷上赌 提交于 2019-12-03 01:44:19
Alex

You have to define POCO_STATIC on the command line and link with both PocoFoundationmt and 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 /libpath:..\poco\lib /WX /nologo exp.obj PocoNetmt.lib PocoFoundationmt.lib

[UPDATE] If you compile with /DPOCO_STATIC, then it isn't necessary to specify the POCO libraries on the linker command line. The header files contain #pragma comment(lib, "PocoXXXmt.lib") statements that should ensure that all the necessary libraries will be linked in.

If you don't compile with /DPOCO_STATIC, then the DLL import libraries will be automatically linked instead. [/UPDATE]

It sounds like the problem is that the PocoNet.lib file is an import library for the poco.dll. So the externs it resolves are to the DLL.

You'll need to find or build a static library for Poco (if possible).

You will need /MT on your code and all its dependencies to statically link to MSVC runtime (MSVCP90.dll/MSVCR90.dll).

That is because PocoNetmt.lib seems to be build with /MT.

If with /MT you still get msvcprt.lib, turn on /verbose and find out which other library drags it. Then recompile/find static build of that.

Another option is to find static PocoNet lib that is built with /MD (so you link statically to it, but dynamically to runtime) and switch everything to /MD.

EDIT: When Poco dll is linked with /MT that does not affect you. But since you want to get rid of it, you (and all your other dependencies) will have to use same /MT flag.

POCO >= 1.4.0 support static with static runtime (and still static with dynamic runtime)

https://raw.github.com/pocoproject/poco/poco-1.4.5/CHANGELOG (search for "debug_static_mt")

do not forget to define POCO_STATIC when including poco headers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!