Skip to content

Commit

Permalink
build: fix linking to libsodium on macOS
Browse files Browse the repository at this point in the history
Currently on I see link failures like the following:
```bash
./configure
<snip>
checking for libsodium with IETF chacha20 variants... yes
<snip>
ar libccan.a
ld ccan/ccan/cdump/tools/cdump-enumstr
ld: library 'sodium' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

The configure check passes under Clang here.

Changelog-Fixed: build: fix linking against libsodium on macOS.
  • Loading branch information
fanquake committed Dec 5, 2024
1 parent f0c5ea2 commit 0005d6b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ LIBRARY_PATH := /usr/local/lib
endif

CPPFLAGS += -DCLN_NEXT_VERSION="\"$(CLN_NEXT_VERSION)\"" -DPKGLIBEXECDIR="\"$(pkglibexecdir)\"" -DBINDIR="\"$(bindir)\"" -DPLUGINDIR="\"$(plugindir)\"" -DCCAN_TAL_NEVER_RETURN_NULL=1
CFLAGS = $(CPPFLAGS) $(CWARNFLAGS) $(CDEBUGFLAGS) $(COPTFLAGS) -I $(CCANDIR) $(EXTERNAL_INCLUDE_FLAGS) -I . -I$(CPATH) $(SQLITE3_CFLAGS) $(POSTGRES_INCLUDE) $(FEATURES) $(COVFLAGS) $(DEV_CFLAGS) -DSHACHAIN_BITS=48 -DJSMN_PARENT_LINKS $(PIE_CFLAGS) $(COMPAT_CFLAGS) $(CSANFLAGS)
CFLAGS = $(CPPFLAGS) $(CWARNFLAGS) $(CDEBUGFLAGS) $(COPTFLAGS) -I $(CCANDIR) $(EXTERNAL_INCLUDE_FLAGS) -I . -I$(CPATH) $(SQLITE3_CFLAGS) $(SODIUM_CFLAGS) $(POSTGRES_INCLUDE) $(FEATURES) $(COVFLAGS) $(DEV_CFLAGS) -DSHACHAIN_BITS=48 -DJSMN_PARENT_LINKS $(PIE_CFLAGS) $(COMPAT_CFLAGS) $(CSANFLAGS)

# If CFLAGS is already set in the environment of make (to whatever value, it
# does not matter) then it would export it to subprocesses with the above value
Expand Down
13 changes: 11 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,13 @@ if command -v "${PKG_CONFIG}" >/dev/null; then
SQLITE3_LDLIBS="$("${PKG_CONFIG}" --silence-errors --libs sqlite3 || :)"
fi

SODIUM_CFLAGS=""
SODIUM_LDLIBS="-lsodium"
if command -v "${PKG_CONFIG}" >/dev/null; then
SODIUM_CFLAGS="$("${PKG_CONFIG}" --silence-errors --cflags libsodium || :)"
SODIUM_LDLIBS="$("${PKG_CONFIG}" --silence-errors --libs libsodium || :)"
fi

POSTGRES_INCLUDE=""
POSTGRES_LDLIBS=""
if command -v "${PG_CONFIG}" >/dev/null; then
Expand All @@ -365,7 +372,7 @@ fi
# Clean up on exit.
trap "rm -f $CONFIG_VAR_FILE.$$" 0

$CONFIGURATOR --extra-tests --autotools-style --var-file=$CONFIG_VAR_FILE.$$ --header-file=$CONFIG_HEADER.$$ --configurator-cc="$CONFIGURATOR_CC" --wrapper="$CONFIGURATOR_WRAPPER" "$CC" ${CWARNFLAGS-$BASE_WARNFLAGS} $CDEBUGFLAGS $COPTFLAGS $CSANFLAGS -I$CPATH -L$LIBRARY_PATH $SQLITE3_CFLAGS $POSTGRES_INCLUDE <<EOF
$CONFIGURATOR --extra-tests --autotools-style --var-file=$CONFIG_VAR_FILE.$$ --header-file=$CONFIG_HEADER.$$ --configurator-cc="$CONFIGURATOR_CC" --wrapper="$CONFIGURATOR_WRAPPER" "$CC" ${CWARNFLAGS-$BASE_WARNFLAGS} $CDEBUGFLAGS $COPTFLAGS $CSANFLAGS -I$CPATH -L$LIBRARY_PATH $SQLITE3_CFLAGS $SODIUM_CFLAGS $POSTGRES_INCLUDE <<EOF
var=HAVE_ZLIB
desc=zlib support
Expand All @@ -388,7 +395,7 @@ int main(void)
var=HAVE_GOOD_LIBSODIUM
desc=libsodium with IETF chacha20 variants
style=DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE
link=-lsodium
link=$SODIUM_LDLIBS
code=
#include <sodium.h>
#include <stdio.h>
Expand Down Expand Up @@ -552,6 +559,8 @@ add_var SQLITE3_CFLAGS "$SQLITE3_CFLAGS"
add_var SQLITE3_LDLIBS "$SQLITE3_LDLIBS"
add_var POSTGRES_INCLUDE "$POSTGRES_INCLUDE"
add_var POSTGRES_LDLIBS "$POSTGRES_LDLIBS"
add_var SODIUM_CFLAGS "$SODIUM_CFLAGS"
add_var SODIUM_LDLIBS "$SODIUM_LDLIBS"
add_var VALGRIND "$VALGRIND"
add_var DEBUGBUILD "$DEBUGBUILD"
add_var COMPAT "$COMPAT" $CONFIG_HEADER.$$
Expand Down
2 changes: 1 addition & 1 deletion external/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ EXTERNAL_INCLUDE_FLAGS += -I external/libsodium/src/libsodium/include \
-I $(TARGET_DIR)/libsodium-build/src/libsodium/include
EXTERNAL_LIBS += ${TARGET_DIR}/libsodium.a
else
LDLIBS += -lsodium
LDLIBS += $(SODIUM_LDLIBS)
endif

ifeq ($(HAVE_ZLIB),1)
Expand Down

0 comments on commit 0005d6b

Please sign in to comment.