Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static Build errors #904

Closed
HawkDeath opened this issue Oct 3, 2017 · 3 comments
Closed

Static Build errors #904

HawkDeath opened this issue Oct 3, 2017 · 3 comments

Comments

@HawkDeath
Copy link

There are problems during static build, about unavailability of symbols in static lib.
There are no hint about necessity of including NN_STATIC_LIB as macro define while building with static linkage.
$ g++ pair.c -pthread -lnanomsg C:\msys64\tmp\ccyDAzLi.o:pair.c:(.text+0x57): undefined reference to `__imp_nn_send' C:\msys64\tmp\ccyDAzLi.o:pair.c:(.text+0x94): undefined reference to `__imp_nn_recv' C:\msys64\tmp\ccyDAzLi.o:pair.c:(.text+0xc7): undefined reference to `__imp_nn_freemsg' C:\msys64\tmp\ccyDAzLi.o:pair.c:(.text+0x10d): undefined reference to `__imp_nn_setsockopt' C:\msys64\tmp\ccyDAzLi.o:pair.c:(.text+0x173): undefined reference to `__imp_nn_socket' C:\msys64\tmp\ccyDAzLi.o:pair.c:(.text+0x1a7): undefined reference to `__imp_nn_bind' C:\msys64\tmp\ccyDAzLi.o:pair.c:(.text+0x1e8): undefined reference to `__imp_nn_shutdown' C:\msys64\tmp\ccyDAzLi.o:pair.c:(.text+0x20d): undefined reference to `__imp_nn_socket' C:\msys64\tmp\ccyDAzLi.o:pair.c:(.text+0x241): undefined reference to `__imp_nn_connect' C:\msys64\tmp\ccyDAzLi.o:pair.c:(.text+0x282): undefined reference to `__imp_nn_shutdown' collect2.exe: error: ld returned 1 exit status

@gdamore
Copy link
Contributor

gdamore commented Oct 3, 2017

Yeah, unfortunately we assume that you want to build a DLL by default. Windows is problematic here -- you have to set things up for either a DLL or a static lib, and they aren't handled the same way.

Define -DNN_STATIC_LIB=1 or you can define NNG_DECL=extern -- either will work.

I will review our approach for nng and for future nanomsg releases.

@gdamore
Copy link
Contributor

gdamore commented Oct 11, 2017

For now I'll add docs to this effect.

@SG7
Copy link

SG7 commented Oct 16, 2017

This are the steps to get a static library: (Linux)

  1. Download nanomsg stable from: https://github.com/nanomsg/nanomsg/1.0.0.zip.
  2. Extract zip file.
  3. Rename nanomsg-1.0.0 to nanomsgsrc.
  4. Delete 1.0.0.zip
  5. Create destination folder beside just-unpacked source folder. You should now have two folders side by side: nanomsgsrc and nanomsglib. 
  6. Switch current directory to source folder (nanomsgsrc ).
  7. Create a directory named build and switch into this new directory. 
  8. Run command: cmake .. -DMAKE_INSTALL_PREFIX=../../nanomsglib/ -DC_BUILD_TYPE=Debug -DNN_STATIC_LIB=1
    DMAKE_INSTALL_PREFIX describes the compilation destination, DC_BUILD_TYPE describes the build type (In this case Debug), and DNN_STATIC_LIB sets the output to static library.
  9. Run command: cmake --build && ctest -C Debug.
  10. Run: cmake --build . --target install
  1. You will now have the static library and include files within the destination folder. The static library will be found at: nanomsglib/lib64/libnanomsg.a , and the include files will be found at: nanomsglib/include.

Or you can use the following script:

#!/bin/bash

#Download nanomsg library 1.0 stable
wget https://github.com/nanomsg/nanomsg/archive/1.0.0.zip

#Extract from archive and delete archive
unzip 1.0.0.zip && rm 1.0.0.zip

#Rename source file
mv nanomsg-1.0.0 nanomsgsrc

#Create destination folder
mkdir nanomsglib

#Switch into nanomsgsrc folder
cd nanomsgsrc

#Create build directory and switch into it
mkdir build && cd build

#Compile
cmake .. -DCMAKE_INSTALL_PREFIX=../../nanomsglib/ -DCMAKE_BUILD_TYPE=Debug -DNN_STATIC_LIB=1
cmake --build .
ctest -C Debug .
cmake --build . --target install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants