michelp / pgsodium

Modern cryptography for PostgreSQL using libsodium.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

dahal opened this issue · comments

Here is the complete error

image

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?

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.

@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 🤞🏼

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.