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

Fix linking of libsodium for linux #553

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Bartel-C8
Copy link
Contributor

@Bartel-C8 Bartel-C8 commented Jan 3, 2023

Bumped into this issue myself when trying to build it on a Docket Debian 9 machine (circleci/node:gallium-stretch-browsers) with:

circleci@38f5f51a4027:~/git/klstr-ctrl$ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=debian
circleci@38f5f51a4027:~/git/klstr-ctrl$ gcc --version
gcc (Debian 8.3.0-6) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
circleci@38f5f51a4027:~/git/klstr-ctrl$ cmake --version
cmake version 3.16.3

CMake suite maintained and supported by Kitware (kitware.com/cmake)
circleci@38f5f51a4027:~/git/klstr-ctrl$ node -v
v16.13.1
-- Detected ZMQ Version - 4.3.5
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29") 
-- Checking for module 'libsodium'
--   Found libsodium, version 1.0.17
-- Found sodium: /usr/lib/x86_64-linux-gnu/libsodium.so  

Compiling works fine, but when trying to run/require the .node module, I got the following error:

node: symbol lookup error: node_modules/zeromq/build/Release/zeromq.node: undefined symbol: sodium_init

I also found a bug report on stackoverflow by coincidence:
https://stackoverflow.com/questions/74796706/node-application-doesnt-start-with-zeromq-node-undefined-symbol-sodium-init

Apparently, as found in this post on stackoverflow: https://stackoverflow.com/questions/57740825/use-libsodium-in-napi, bindings.gyp also needs the libsodium libraries dependency in order to link properly.

I did not change anything for Windows. As I suspect everything works okay there.
I guess it's also OS/gcc/cmake/node related. As on my other VM build machine (Ubuntu 20.04 / gcc 9.4.0 / cmake 3.16.3 / node v18.12.1), I didn't have linker problems.
I switched to an older build system as my findings of incompatible GLIBC versions, as described here: #529 (comment)

For setting up the docker build environment (maybe for future reference, as it was quite a pain: python 3.6 dependency, cmake 3.13+ dependency (https://stackoverflow.com/questions/68986713/git-bash-on-windows-cmake-error-the-source-directory-does-not-exists#comment121926826_68987727) / gcc 7+ (c++17) ):

  # Add the repository key
  - wget https://people.debian.org/~paravoid/python-all/unofficial-python-all.asc
  - sudo mv unofficial-python-all.asc /etc/apt/trusted.gpg.d/
  # Add the repository to your sources.list
  - sudo apt-get remove python3.5 gcc
  - sudo apt autoremove
  - echo "deb http://people.debian.org/~paravoid/python-all stretch main" | sudo tee /etc/apt/sources.list.d/python-all.list
  - echo "deb http://ftp.debian.org/debian stretch-backports-sloppy main" | sudo tee /etc/apt/sources.list.d/backports.list
  - echo "deb http://ftp.debian.org/debian buster main" | sudo tee /etc/apt/sources.list.d/buster.list
  - sudo apt-get update
  - sudo apt-get install -y --no-install-recommends --no-install-suggests python3.6 pkg-config libsodium-dev
  - sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
  - sudo apt-get install -y -t stretch-backports-sloppy libarchive13
  - sudo apt-get install -y -t stretch-backports cmake
  - sudo apt-get install -y -t buster gcc-8 g++ build-essential
  - export NODE_OPTIONS="--max-old-space-size=4096"

@Bartel-C8
Copy link
Contributor Author

Build fails now:

Actually, it is a correct bug/warning, as currently for linux builds, libsodium is not used, but defined as statically loaded:
https://github.com/zeromq/zeromq.js/actions/runs/3642070979/jobs/6148750421

-- Checking for module 'libsodium'
--   No package 'libsodium' found
-- Checking for module 'sodium'
--   No package 'sodium' found
CMake Warning (dev) at /home/runner/cmake/cmake-3.25.0-linux-x86_64/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:438 (message):
-- Could NOT find sodium (missing: SODIUM_LIBRARIES SODIUM_INCLUDE_DIRS) 
  The package name passed to `find_package_handle_standard_args` (sodium)
  does not match the name of the calling package (Sodium).  This can lead to
  problems in calling code that expects `find_package` result variables
  (e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  builds/cmake/Modules/FindSodium.cmake:42 (find_package_handle_standard_args)
  CMakeLists.txt:266 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning at CMakeLists.txt:280 (message):
-- Using tweetnacl for CURVE security
-- Looking for kqueue
  libsodium not installed, instead using builtin tweetnacl, you may want to
  install libsodium and run cmake again

So I will add libsodium to the linux build environment?

We should consider adding libsodium-cmake as a build dependency from source maybe, to make it more easy/clear?

https://github.com/robinlinden/libsodium-cmake

@@ -76,6 +76,7 @@
['OS != "win"', {
'libraries': [
'<(module_root_dir)/build/libzmq/lib/libzmq.a',
"<!@(pkg-config libsodium --libs)",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be needed here since it is handled inside CMake.
Do you get an error without this?

Copy link
Contributor Author

@Bartel-C8 Bartel-C8 Jan 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know. But somehow it is needed for node-gyp in order to resolve symbols properly!
(In older build systems)
I verified this on the setup described above.

No compile error without this, but a runtime error:

bartel@ubuntu:~/Desktop/linux-unpacked$ node test.js 
node: symbol lookup error: node_modules/zeromq/build/Release/zeromq.node: undefined symbol: sodium_init
bartel@ubuntu:~/Desktop/linux-unpacked$ cat test.js 
const zeromq = require("./node_modules/zeromq/build/Release/zeromq.node")
console.log(zeromq)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I can confirm that this solved my issue with compiling native library for usage with electron (requires build against specific node version) on Linux (up-to-date Manjaro/Arch). Is there any chance to have this fix in official package? Cheers, Martin

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

Successfully merging this pull request may close these issues.

None yet

3 participants