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

Running into fatal error: 'sodium.h' file not found error during installation #77

Open
dahal opened this issue Feb 20, 2023 · 4 comments

Comments

@dahal
Copy link

dahal commented Feb 20, 2023

Here is the complete error

image

@dahal
Copy link
Author

dahal commented Feb 20, 2023

This appears to be because of conflict on my local postgres installation. I initially installed postgres using brew, and uninstalled it. Reinstalled using postgres and this issue was resolved. However, i am running into another issue now.

      ...
     (maybe you meant: _pgsodium_randombytes_buf, _pgsodium_randombytes_buf_deterministic , _pg_finfo_pgsodium_randombytes_buf_deterministic , _pg_finfo_pgsodium_randombytes_buf )
  "_randombytes_buf_deterministic", referenced from:
      _pgsodium_randombytes_buf_deterministic in random.o
     (maybe you meant: _pgsodium_randombytes_buf_deterministic, _pg_finfo_pgsodium_randombytes_buf_deterministic )
  "_randombytes_random", referenced from:
      _pgsodium_randombytes_random in random.o
     (maybe you meant: _pgsodium_randombytes_random, _pg_finfo_pgsodium_randombytes_random )
  "_randombytes_uniform", referenced from:
      _pgsodium_randombytes_uniform in random.o
     (maybe you meant: _pgsodium_randombytes_uniform, _pg_finfo_pgsodium_randombytes_uniform )
  "_sodium_base642bin", referenced from:
      _pgsodium_sodium_base642bin in helpers.o
     (maybe you meant: _pg_finfo_pgsodium_sodium_base642bin, _pgsodium_sodium_base642bin )
  "_sodium_bin2base64", referenced from:
      _pgsodium_sodium_bin2base64 in helpers.o
     (maybe you meant: _pg_finfo_pgsodium_sodium_bin2base64, _pgsodium_sodium_bin2base64 )
  "_sodium_init", referenced from:
      __PG_init in pgsodium.o
  "_sodium_malloc", referenced from:
      __PG_init in pgsodium.o
  "_sodium_memcmp", referenced from:
      _crypto_aead_det_xchacha20_decrypt_detached in crypto_aead_det_xchacha20.o
      _crypto_signcrypt_tbsbr_verify_after in signcrypt_tbsbr.o
  "_sodium_memzero", referenced from:
      _context_cb_zero_buff in aead.o
      _context_cb_zero_buff in auth.o
      _context_cb_zero_buff in box.o
      _context_cb_zero_buff in derive.o
      _context_cb_zero_buff in hash.o
      _context_cb_zero_buff in helpers.o
      _context_cb_zero_buff in hmac.o
      ...
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pgsodium.so] Error 1
ERROR: command returned 2: make PG_CONFIG=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config all

Could it be because of Mac OS M2? Can anyone confirm?

@michelp
Copy link
Owner

michelp commented Feb 20, 2023

Did you delete your original comment? I'm just confused because the email notification I got contained different information.

It sounds like you don't have libsodium installed, although I don't have a Mac so cannot confirm what the steps are to build for it.

Most of the mac users I've worked with to date just use docker to get it working but I can see the value in a native build. If you (or someone who has a mac that can confirm) can get the steps to get it working we can add macos to the github action test runner matrix to ensure that it is tested on that platform for all commits. A similar work in progress is happening now for Windows in another thread.

@dahal
Copy link
Author

dahal commented Feb 21, 2023

@michelp thanks for getting back. I was basically trying all diff ways to install it and all installation methods are leading to the same error. And yes, I did install libsodium before installing pgsodium. I have not tried with docker, my app is not dockerized yet, native build would really help 🤞🏼

@rockisch
Copy link

rockisch commented Dec 4, 2023

Hey, I was also having some issues linking the project with libsodium on a M2, I feel like it's a good idea to share what I did here.

First, even after installing libsodium with brew (the 'main' MacOS package manager), gcc was still unable to find the libsodium headers and lib files, I guess MacOS's gcc doesn't search for brew installed libs. Running:

export C_INCLUDE_PATH=/opt/homebrew/include

before make allowed it to find the headers, but I couldn't find a variable that allowed it to find the lib.

I decided to just build libsodium directly following the official docs, and that worked. However, trying to build again raised the following warning, followed by a bunch of 'undefined symbol' errors:

ld: warning: ignoring file /usr/local/lib/libsodium.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64

These were the gcc arguments:

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Werror=unguarded-availability-new -Wendif-labels -Wmissing-format-attribute -Wcast-function-type -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro  -Os -mmacosx-version-min=10.13 -arch arm64 -arch x86_64  -bundle -o pgsodium.so src/aead.o src/auth.o src/box.o src/crypto_aead_det_xchacha20.o src/derive.o src/hash.o src/helpers.o src/hmac.o src/kdf.o src/kx.o src/pgsodium.o src/pwhash.o src/random.o src/secretbox.o src/secretstream.o src/sha.o src/sign.o src/signcrypt.o src/signcrypt_tbsbr.o src/stream.o -L/Applications/Postgres.app/Contents/Versions/15/lib   -L/Applications/Postgres.app/Contents/Versions/15/lib -L/Applications/Postgres.app/Contents/Versions/15/lib -L/Applications/Postgres.app/Contents/Versions/15/lib  -L/Applications/Postgres.app/Contents/Versions/15/lib -Wl,-dead_strip_dylibs   -lsodium -bundle_loader /Applications/Postgres.app/Contents/Versions/15/bin/postgres

The specific issue was with the -arch arm64 -arch x86_64 arguments. Removing the -arch x86_64 arg and running gcc directly correctly built the project, and copying the files to their expected locations also worked as expected.

I'm not sure if there's anything that can be done about the homebrew stuff besides adding hardcoded search paths to GCC, but I think ideally the -arch x86_64 argument should not be set when building on M1/2/3.

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