lightning icon indicating copy to clipboard operation
lightning copied to clipboard

macos apple silicon: We need a libsodium >= 1.0.4

Open grubles opened this issue 1 month ago • 12 comments

So on macOS Apple Silicon, the libsodium directory is correctly set when running configure, but it still complains:

Setting SODIUM_CFLAGS... -I/opt/homebrew/Cellar/libsodium/1.0.20/include
Setting SODIUM_LDLIBS... -L/opt/homebrew/Cellar/libsodium/1.0.20/lib -lsodium

...

*** We need a libsodium >= 1.0.4 (released 2015-06-11).

Problem is I have libsodium installed though:

% brew info libsodium
==> libsodium: stable 1.0.20 (bottled), HEAD
NaCl networking and cryptography libraryhttps://libsodium.org/
Installed
/opt/homebrew/Cellar/libsodium/1.0.20 (78 files, 904.6KB) *

grubles avatar Nov 13 '25 17:11 grubles

I believe @ddustin figured out that it is a bad version comparison code somewhere where it thinks 1.0.4 >1.0.20 which is not the case in semver.

daywalker90 avatar Nov 13 '25 18:11 daywalker90

I might remember it wrong but that what it looked like to me

daywalker90 avatar Nov 13 '25 18:11 daywalker90

Can you try the new steps under macOS Apple Silicon?

https://github.com/ElementsProject/lightning/blob/master/doc/getting-started/getting-started/installation.md

Can you also post the entire output from ./configure?

I definitely ran into this issue and IIRC it was including from one homebrew installation and linking from another.

The version error just means it wasn't able to compile the sodium test, not necessarily that you have an out of date version.

ddustin avatar Nov 13 '25 19:11 ddustin

Can you try the new steps under macOS Apple Silicon?

Tried that and the libsodium error still occurs.

Can you also post the entire output from ./configure?

% ./configure                                                                                                                                                       
CSANFLAGS =                                                                                                                                                                            
-n Compiling ccan/tools/configurator/configurator...                         
done                                                                                       
Making autoconf users comfortable... yes
checking for off_t is 32 bits... no                                                        
checking for __alignof__ support... yes
checking for asprintf() declaration... yes
checking for __attribute__((cold)) support... yes                                          
checking for __attribute__((const)) support... yes                                         
checking for __attribute__((deprecated)) support... yes                                    
checking for __attribute__((nonnull)) support... yes                                       
checking for __attribute__((returns_nonnull)) support... yes                               
checking for __attribute__((sentinel)) support... yes                                      
checking for __attribute__((pure)) support... yes                                                                                                                                      
checking for __attribute__((may_alias)) support... yes                                                                                                                                 
checking for __attribute__((noreturn)) support... yes                                                                                                                                  
checking for __attribute__ format printf support... yes                                    
checking for __attribute__((unused)) support... yes                                        
checking for __attribute__((used)) support... yes                                          
checking for backtrace() in <execinfo.h>... yes              
checking for big endian... no
checking for <byteswap.h>... no
checking for __builtin_choose_expr support... yes          
checking for __builtin_clz support... yes
checking for __builtin_clzl support... yes
checking for __builtin_clzll support... yes                                                
checking for __builtin_ctz support... yes
checking for __builtin_ctzl support... yes
checking for __builtin_ctzll support... yes                                                
checking for __builtin_constant_p support... yes                                           
checking for __builtin_expect support... yes
checking for __builtin_ffs support... yes                                                  
checking for __builtin_ffsl support... yes
checking for __builtin_ffsll support... yes
checking for __builtin_popcount support... yes                
checking for __builtin_popcountl support... yes                                            
checking for __builtin_popcountll support... yes                                           
checking for __builtin_types_compatible_p support... yes   
checking for <intrinsics.h>... no
checking for struct timespec declaration... yes                                            
checking for clock_gettime() declaration... yes            
checking for compound literal support... yes
checking for fchdir support... yes
checking for <err.h>... yes                                                                
checking for for loop declaration support... yes                                           
checking for flexible array member support... yes                                          
checking for getpagesize() in <unistd.h>... yes              
checking for isblank() in <ctype.h>... yes
checking for little endian... yes
checking for memmem in <string.h>... yes                                                   
checking for memrchr in <string.h>... no
checking for mmap() declaration... yes
checking for /proc/self/maps exists... no                                                              
checking for qsort_r cmp takes trailing arg... no
checking for __attribute__((section)) and __start/__stop... no
checking for stack grows upwards... no
checking for statement expression support... yes
checking for <sys/filio.h>... yes
checking for <sys/termios.h>... yes
checking for <sys/unistd.h>... yes
checking for __typeof__ support... yes
checking for unaligned access to int... yes
checking for utime() declaration... yes
checking for __attribute__((warn_unused_result))... yes
checking for #pragma omp and -fopenmp support... no
checking for <valgrind/memcheck.h>... no
checking for working <ucontext.h... no
checking for __builtin_cpu_supports()... no
checking for closefrom() offered by system... no
checking for F_CLOSEM defined for fctnl.... no
checking for close_range syscall available as __NR_close_range.... no
checking for F_MAXFD defined for fcntl.... no
checking for zlib support... yes
checking for libsodium with IETF chacha20 variants... no
checking for sqlite3... no
checking for postgres... no
checking for User Statically-Defined Tracing (USDT)... no
checking for compiler is GCC... no
checking for GCC version is 7 or above... no
Writing variables to config.vars.15141... yes
Writing header to ccan/config.h.15141... yes
-n checking for python3-mako... 
not found
-n checking for lowdown... 
found
-n checking for sha256sum... 
found
-n checking for jq... 
found
Setting PREFIX... /usr/local
Setting CC... cc
Setting CONFIGURATOR_CC... cc
Setting CWARNFLAGS... -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition -Werror
Setting CDEBUGFLAGS... -std=gnu11 -g -gdwarf-4 -fno-standalone-debug -fstack-protector-strong
Setting COPTFLAGS... -Og
Setting SDKROOT... /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk
CSANFLAGS not found
FUZZFLAGS not found
FUZZER_LIB not found
LLVM_LDFLAGS not found
Setting SQLITE3_CFLAGS... -I/opt/homebrew/opt/sqlite/include
Setting SQLITE3_LDLIBS... -L/opt/homebrew/opt/sqlite/lib -lsqlite3
Setting POSTGRES_INCLUDE... -I/opt/homebrew/include/postgresql@14
Setting POSTGRES_LDLIBS... -L/opt/homebrew/lib/postgresql@14 -lpq
Setting SODIUM_CFLAGS... -I/opt/homebrew/Cellar/libsodium/1.0.20/include
Setting SODIUM_LDLIBS... -L/opt/homebrew/Cellar/libsodium/1.0.20/lib -lsodium
Setting VALGRIND... 0
Setting DEBUGBUILD... 0
Setting COMPAT... 1
Setting PYTEST... python3 -m pytest
Setting STATIC... 0
Setting CLANG_COVERAGE... 0
Setting ASAN... 0
Setting UBSAN... 0
Setting TEST_NETWORK... regtest
Setting HAVE_PYTHON3_MAKO... 0
Setting SHA256SUM... sha256sum
Setting FUZZING... 0
Setting RUST... 1
Setting PYTHON... python3
Setting SED... gsed
*** We need a libsodium >= 1.0.4 (released 2015-06-11).

grubles avatar Nov 13 '25 19:11 grubles

What result are you getting for these commands:

which pkg-config
pkg-config --cflags libsodium
pkg-config --libs libsodium
ls  /usr/local/bin/brew
ls  /opt/homebrew/bin/brew
echo $PATH

ddustin avatar Nov 13 '25 19:11 ddustin

user@mbp lightning % which pkg-config
/opt/homebrew/bin/pkg-config

user@mbp lightning % pkg-config --cflags libsodium
-I/opt/homebrew/Cellar/libsodium/1.0.20/include

user@mbp lightning % pkg-config --libs libsodium
-L/opt/homebrew/Cellar/libsodium/1.0.20/lib -lsodium

user@mbp lightning % ls  /usr/local/bin/brew
ls: /usr/local/bin/brew: No such file or directory

user@mbp lightning % ls  /opt/homebrew/bin/brew
/opt/homebrew/bin/brew

user@mbp lightning % echo $PATH
/opt/homebrew/opt/:/opt/homebrew/opt/gnu-getopt/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/usr/local/go/bin:/opt/homebrew/opt/gnu-getopt/bin:/Users/user/.cargo/bin:/Users/user/Library/Python/3.10/bin:/Users/user/.protostar/dist/protostar:/Users/user/Library/Python/3.10/bin:/Users/user/.protostar/dist/protostar

grubles avatar Nov 13 '25 20:11 grubles

Please try compiling this with "-Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition -Werror"?

#include <sodium.h>
#include <stdio.h>
#include <string.h>

int main(void)
{
	crypto_secretstream_xchacha20poly1305_state crypto_state;
	unsigned char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES];
	unsigned char key[crypto_secretstream_xchacha20poly1305_KEYBYTES];

	crypto_secretstream_xchacha20poly1305_keygen(key);
	crypto_secretstream_xchacha20poly1305_init_push(&crypto_state, header,
	                                                key);
	printf("%p\n", crypto_aead_chacha20poly1305_ietf_encrypt);
	printf("%d\n", crypto_aead_chacha20poly1305_ietf_NPUBBYTES);
	return 0;
}

Could be clang warning about something in that code...

rustyrussell avatar Nov 16 '25 03:11 rustyrussell

% cc -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition -Werror test.c   
Undefined symbols for architecture arm64:
  "_crypto_aead_chacha20poly1305_ietf_encrypt", referenced from:
      _main in test-b9a867.o
  "_crypto_secretstream_xchacha20poly1305_init_push", referenced from:
      _main in test-b9a867.o
  "_crypto_secretstream_xchacha20poly1305_keygen", referenced from:
      _main in test-b9a867.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

grubles avatar Nov 18 '25 13:11 grubles

I ran into the same issue and I thought it was caused by my two installs of brew but you clearly only have the silicone brew installed.

What's odd is the headers have chacha but the linked libraries don't. This reads to me that it's picking up the headers from one version of sodium and linking from another.

Can you do a brew reinstall libsodium and try compiling that file again?

If that doesn't reveal anything, try uninstalling libsodium from brew entirely and see if you can't get a different error (ie a header include failure).

ddustin avatar Nov 18 '25 13:11 ddustin

Do you still have a /usr/local folder? I believe it's meant to be deleted or at least empty after switching to the silicon brew version.

ls /usr/local

If there are traces of the old brew, brew has an uninstall script mentioned here:

https://github.com/Homebrew/install?tab=readme-ov-file#uninstall-homebrew

Be sure to run it with the "--path /usr/local" option.

ddustin avatar Nov 18 '25 14:11 ddustin

Well this isn't a macOS install that was migrated from x86. It was created on Apple Silicon. I will try reinstalling and uninstalling libsodium.

grubles avatar Nov 18 '25 14:11 grubles

Reinstalling didn't help and uninstalling just caused it to complain about missing the libsodium header.

% cc -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition -Werror test.c
test.c:1:10: fatal error: 'sodium.h' file not found
#include <sodium.h>
         ^~~~~~~~~~
1 error generated.

grubles avatar Nov 18 '25 15:11 grubles