After upgrading to Xcode 15, I have been having problems with dynamic libraries linking at run time. I compiled netcdf-c from source using cmake and installed it in /usr/local.
Consider the simple test program.
#import <netcdf.h>
int main() {
nc_strerror(0);
}
I can build and link it using the following command.
clang -o test main.c -lnetcdf -L/usr/local/lib
Everything compiles fine but I get a runtime error when running.
% ./test
dyld[67988]: Symbol not found: _nc_strerror
Referenced from: <31EE4C15-A028-32F2-8524-123CC396EB82> /Users/***/Desktop/test/test
Expected in: <no uuid> unknown
zsh: abort ./test
I can confirm that the symbol is present in libnetcdf.dylib.
% nm libnetcdf.dylib| grep _nc_strerror
0000000000006070 T _nc_strerror
I cannot figure out why this isn't loading this symbol. The only thing I can guess it make be related to needing to disable CMAKE_SKIP_RPATH when build the HDF5 library because I was getting an @rpath error with the szip library.
% make
[ 0%] Building C object src/CMakeFiles/H5detect.dir/H5detect.c.o
[ 0%] Linking C executable ../bin/H5detect
[ 0%] Built target H5detect
[ 0%] Building C object src/CMakeFiles/H5make_libsettings.dir/H5make_libsettings.c.o
[ 0%] Linking C executable ../bin/H5make_libsettings
[ 0%] Built target H5make_libsettings
[ 0%] Create H5lib_settings.c
dyld[69160]: Library not loaded: @rpath/libszip.2.1.dylib
Referenced from: <893565BE-D306-3437-AA9A-67027F43FC49> /Users/***/Libraries/hdf5-1.14.2/build/bin/H5make_libsettings
Reason: tried: '/Users/***/Libraries/hdf5-1.14.2/build/lib/libszip.2.1.dylib' (no such file), '/Users/***/Libraries/hdf5-1.14.2/build/bin/libszip.2.1.dylib' (no such file), '/Users/***/Libraries/hdf5-1.14.2/build/bin/../lib/libszip.2.1.dylib' (no such file), '/Users/***/Libraries/hdf5-1.14.2/build/bin/libszip.2.1.dylib' (no such file), '/Users/***/Libraries/hdf5-1.14.2/build/lib/libszip.2.1.dylib' (no such file), '/Users/***/Libraries/hdf5-1.14.2/build/bin/libszip.2.1.dylib' (no such file), '/Users/***/Libraries/hdf5-1.14.2/build/bin/../lib/libszip.2.1.dylib' (no such file), '/Users/***/Libraries/hdf5-1.14.2/build/bin/libszip.2.1.dylib' (no such file)
/bin/sh: line 1: 69160 Abort trap: 6 /Users/***/Libraries/hdf5-1.14.2/build/bin/H5make_libsettings H5lib_settings.c
make[2]: *** [src/gen_SRCS.stamp2] Error 134
make[1]: *** [src/CMakeFiles/gen_hdf5-static.dir/all] Error 2
make: *** [all] Error 2
Also I build the szip library from source using cmake and installed it in /usr/local/lib.
They have a new linker that might be the problem. Maybe this from the release notes of Xcode can help? "A new linker has been written to significantly speed up static linking. It’s the default for all macOS, iOS, tvOS and visionOS binaries and anyone using the “Mergeable Libraries” feature. The classic linker can still be explicitly requested using -ld64, and will be removed in a future release."