Search code examples
cmingwstatic-linkingmxenanomsg

Can't link in libnanomsg for Windows MinGW, cross compiling using MXE


I am trying to build nanomsg on mingw, cross compiling from ubuntu using mxe. The target host is x86_64. I built it fine but it won't link. I am getting issues like

undefined reference to 'imp__nn_freemsg'

I think it's a static lib issue. I built again using

 ./configure --enable-static --disable-shared ...

Same issue. Are there any linker flags I need to put in the gcc build line after I link in libnanomsg.a?


Solution

  • There are many defines that will be set if you build with VS, using cmake. Some are located in src/nn.h, others are scattered around. By the way, the 'imp__**' issue is always a failure to link it statically.

    Passing these flags will link it:

    -D_WIN32 -DNN_EXPORTS -DNN_HAVE_MINGW -DNN_HAVE_WINDOWS -DNN_USE_LITERAL_IFADDR=1 -DSTATICLIB