I’m trying to add BoringSSL as a dependency of my library, using C++ with CMake for Android.
Here is what I’m doing:
add_library(mylib STATIC
foo.cpp bar.cpp .....)
ExternalProject_Add(
boringssl
GIT_REPOSITORY "https://github.com/google/boringssl.git"
GIT_TAG "origin/master"
SOURCE_DIR "external/boringssl"
STEP_TARGETS crypto ssl
CMAKE_ARGS "-DOPENSSL_SMALL=TRUE"
)
add_dependencies(mylib boringssl)
target_link_directories(mylib PRIVATE
"${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/install/lib")
target_link_libraries(mylib PRIVATE
crypto ssl)
The linker for “mylib” fails with “ld.lld: error: unable to find library -lcrypto” and “-lssl” and here is the weird thing:
Even though I use target_link_directories
, the linker command line as printed out does not include the .../boringssl/install/lib
directory. This directory doesn’t exist at configure time (since ExternalProject_Add runs at build time) but that shouldn’t be a problem, right?
I must be doing something wrong, what is it?
Broader question – I want to include BoringSSL as a dependency of my library, what’s the best way to do it if not ExternalProject_Add
?
Edit: here is the linker command line, as you can see it’s missing the link directory (my library is called srtc):
–target=aarch64-none-linux-android29 –sysroot=/mnt/android/sdk/ndk/27.2.12479018/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fno-exceptions -fno-rtti -fno-limit-debug-info -static-libstdc++ -Wl,–build-id=sha1 -Wl,–no-rosegment -Wl,–no-undefined-version -Wl,–fatal-warnings -Wl,–no-undefined -Qunused-arguments -shared -Wl,-soname,libsrtctest.so -o /home/kman/Android/proj-srtc/build/intermediates/cxx/Debug/5963472j/obj/arm64-v8a/libsrtctest.so CMakeFiles/srtctest.dir/jni_class_map.cpp.o CMakeFiles/srtctest.dir/jni_error.cpp.o CMakeFiles/srtctest.dir/jni_util.cpp.o CMakeFiles/srtctest.dir/jni_peer_connection.cpp.o CMakeFiles/srtctest.dir/srtctest_main.cpp.o srtc/libsrtc.a -landroid -llog -lcrypto -lssl -latomic -lm && :
ld.lld: error: unable to find library -lcrypto
ld.lld: error: unable to find library -lssl
3