3.26.3: curltest with static openssl fails to compile due to missing -ldl argument
Compiling cmake 3.26.3 on Rocky Linux 8.5 on ARM, with my own built static libraries for SSL, the curltest program fails to link because the -ldl library is missing from the link line:
-- Found OpenSSL: /data/src/openssl/dist/lib/libcrypto.a (found version "1.1.1t")
...
arm64-tools-linux-gnu-gcc -O2 -fPIC -static-libgcc -w -O3 -DNDEBUG -static-libgcc -static-libstdc++ CMakeFiles/curltest.dir/curltest.c.o -o curltest lib/libcmcurl.a /data/src/openssl/dist/lib/libssl.a /data/src/openssldist/lib/libcrypto.a -lpthread ../cmnghttp2/libcmnghttp2.a ../cmzlib/libcmzlib.a
/data/src/openssl/dist/lib/libcrypto.a(dso_dlfcn.o):dso_dlfcn.c:function dlfcn_globallookup: error: undefined reference to 'dlopen'
/data/src/openssl/dist/lib/libcrypto.a(dso_dlfcn.o):dso_dlfcn.c:function dlfcn_globallookup: error: undefined reference to 'dlsym'
Weirdly I didn't see this issue building on Rocky Linux 8.5 on Intel. I can't explain why they wouldn't be the same.
If my SSL were built dynamically then the libcrypto.so would refer to -ldl and ld would pull it in by itself, but because I'm using static libraries the -ldl has to be added separately.
I'm setting PKG_CONFIG_PATH
to find the right .pc file, and it DOES appear to be found because it chooses my special openssl libraries and not the system openssl libraries, and in my version of the libcrypto.pc file I do see the right content:
Libs.private: -ldl -pthread