[zeromq-dev] Static library in Visual Studio (SOLVED)
malist
mailing.list at manageapp.com
Tue Nov 9 02:36:17 CET 2010
Here is what I have done to get zmq to compile as static library using Visual Studio Express 2008 in WinXP:
First I had to add 2 more includes to my project to be able to compile in Windows:
#if VERSIONWIN
#include "..\zmq\zeromq2\src\stdint.hpp" // for windows
#include "..\zmq\zeromq2\include\zmq.h" // for windows
#else
#include "zmq.h" // zmq library, OSX XCode
#endif
---
Static compile with newbie-try-and-see-what-happens-method:
1) I changed in libzmq project Property Pages / General / Configuration type --> Static Library (.lib)
2) I changed C/C++ Code generation Runtime Library --> Multi-threaded (/MT)
* for debug build --> Multi-threaded debug (/MTd)
Then I tried to compile my program and I got link errors like this:
MA_Zmq_Plugin.obj : error LNK2019: unresolved external symbol __imp__zmq_version referenced in function...
3) Then I googled discussions (http://www.mail-archive.com/zeromq-dev@lists.zeromq.org/msg03925.html) and changed both zmq.h and zmq_utils.h:
/* Win32 needs special handling for DLL exports */
#if defined _WIN32
# if defined DLL_EXPORT
# define ZMQ_EXPORT __declspec(dllexport)
# else
# define ZMQ_EXPORT __declspec(dllimport)
# endif
#else
# define ZMQ_EXPORT
#endif
-->
#if defined _MSC_VER
# if defined ZMQ_STATIC
# define DLL_EXPORT
# endif
# if defined DLL_EXPORT
# define ZMQ_EXPORT __declspec(dllexport)
# else
# define ZMQ_EXPORT __declspec(dllimport)
# endif
#else
# define ZMQ_EXPORT
#endif
4) I added to C/C++ / Preprocessor / Preprocessor definitions --> ZMQ_STATIC
5) I compiled zeromq and copied zeromq2\builds\msvc\Release\libzmq.lib to my own project folder as libzmq.lib. Library size was 18467 Kb.
* for debug build I copied zeromq2\builds\msvc\Debug\libzmq.lib to my own project folder as libzmq_debug.lib. Library size was 7356 Kb.
I got 47 warnings like one below, I just ignored them:
z:\cpp\examples\zmq\zeromq2\include\zmq.h(48) : warning C4005: 'DLL_EXPORT' : macro redefinition
command-line arguments : see previous definition of 'DLL_EXPORT'
6) I added Linker / Input / Additional dependencies --> libzmq.lib
* for debug build: libzmq_debug.lib
I compiled my own project and got more link errors, then I Googled again and added:
7) Linker / Input / Additional dependencies --> ws2_32.lib
8) I added C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib\RpcRT4.lib to my project with drag & drop.
Now I was able to get zmq to build statically and it worked, both release and debug!
My final non-debug product size is 351 Kb.
---
I still get 1 link warning when I build non-debug version, but I don't know if it has any side effects:
libzmq.lib(zmq.obj) : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance.
---
Now I had only one problem. Debug build did not stop into breakpoints when debugging. Debugger said that symbols have not been loaded.
After debug build I got 47 linker warnings like this:
libzmq_debug.lib(clock.obj) : warning LNK4204: 'Z:\cpp\MA_Plugin_v12\Objs\Debug\vc90.pdb' is missing debugging information for referencing module; linking object as if no debug info.
Then I Googled again and found:
http://www.gamedev.net/reference/articles/article1583.asp
"I recommend compiling with C7 compatible debug (/Z7) for a static library. This allows debugging info to be placed inside the .lib files, so it saves the hassle of locating the program database if you generate it separately."
I recompiled libzmq debug build with with C7 compatible debug (/Z7). Library size increased to 16899 Kb and I got rid of all linker warnings in my own program. Still debug breakpoints do not work.
So one question remains after almost 4 hours of testing:
How can I can stop in my own project breakpoints?
Thanks for help.
Regards,
Pasi Mankinen
Finland
More information about the zeromq-dev
mailing list