-
Notifications
You must be signed in to change notification settings - Fork 77
[fix] Force static libraries to be linked when LINK_STATIC is enabled #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix] Force static libraries to be linked when LINK_STATIC is enabled #28
Conversation
### Motivation Currently, even with `LINK_STATIC=ON` option, dynamic libraries could still be linked. For example, on macOS, the following libcurl library will be found: ``` /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/lib/libcurl.tbd ``` Then, the `libpulsar.dylib` will link to `/usr/lib/libcurl.4.dylib`, which is not a dynamic library. ### Modifications When `LINK_STATIC` is enabled, change `CMAKE_FIND_LIBRARY_SUFFIXES` to `.a` for non-MSVC compilers so that only static libraries could be found except OpenSSL, which should not be linked statically. In addition, use `find_package` as much as possible instead of raw usages of `find_path` and `find_library`.
|
@merlimat @Demogorgon314 @RobertIndie Now all tests passed, PTAL. Currently I'm working on fixing the Windows build when |
|
@BewareMyPower CMake is now failing to find OpenSSL on Mac (installed with brew): |
|
@merlimat I just tested again in my local env. Here is my command (just test the default cmake -Wno-dev \
-DCMAKE_PREFIX_PATH="/usr/local" \
-DBUILD_TESTS=OFF -DBUILD_PERF_TOOLS=ON \
-B buildHere are my outputs after this PR: Here are my outputs before this PR (just added the same logs): The patch to add logs: diff --git a/CMakeLists.txt b/CMakeLists.txt
index d3876f8..5952576 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -135,6 +135,8 @@ set(OPENSSL_USE_STATIC_LIBS FALSE)
find_package(OpenSSL REQUIRED)
set(RECORD_OPENSSL_SSL_LIBRARY ${OPENSSL_SSL_LIBRARY})
set(RECORD_OPENSSL_CRYPTO_LIBRARY ${OPENSSL_CRYPTO_LIBRARY})
+message("RECORD_OPENSSL_SSL_LIBRARY: " ${RECORD_OPENSSL_SSL_LIBRARY})
+message("RECORD_OPENSSL_CRYPTO_LIBRARY: " ${RECORD_OPENSSL_CRYPTO_LIBRARY})
unset(OPENSSL_FOUND CACHE)
unset(OPENSSL_INCLUDE_DIR CACHE)
@@ -270,6 +272,9 @@ endif()
find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})
find_package(OpenSSL REQUIRED)
+message("OPENSSL_INCLUDE_DIR: " ${OPENSSL_INCLUDE_DIR})
+message("OPENSSL_SSL_LIBRARY: " ${OPENSSL_SSL_LIBRARY})
+message("OPENSSL_CRYPTO_LIBRARY: " ${OPENSSL_CRYPTO_LIBRARY})
if (BUILD_TESTS)
find_path(GTEST_INCLUDE_PATH gtest/gtest.h)It looks like this PR brings some unexpected changes, I will investigate and fix it soon. |
|
I think there’s one extra find_package for OpenSSL at the beginning (3 calls in total). It should be removed. Additionally, we should still use static lib for OpenSSL too |
It is exactly what I am confused. From https://pulsar.apache.org/docs/client-libraries-cpp#install-dependencies
I also found the original PR (apache/pulsar#6458) from @jiazhai.
Should we revert these complicated logic to find and link OpenSSL dependency? |
|
I think that if we don't do that, there can be linking problems between different OpenSSL version (eg: 1.1.1 vs 3.0.4) |
Yeah, I agree. The ABI compatibility changed a lot, see https://abi-laboratory.pro/?view=timeline&l=openssl In addition,
I think we should remove |
### Motivation See discussions here: apache#28 (comment) The original purpose to not include static OpenSSL library in `libpulsarwithnossl.so` and `libpulsarwithdeps.a` is apache/pulsar#6458. However, the ABI compatibility of OpenSSL is not good. If the Pulsar C++ library links dynamically to OpenSSL and the user only changes the OpenSSL dynamic library, some symbols might not be found. ### Modifications Use `LINK_STATIC` option to determine whether to link to OpenSSL library statically. After that, there are only 3 libraries generated when `LINK_STATIC` is ON. - `libpulsar.so`: the dynamic pulsar-client-cpp library. - `libpulsar.a`: the static pulsar-client-cpp library. When it's used, users must link to all 3rd party dependencies (OpenSSL, curl, etc.) - `libpulsarwithdeps.a`: the static pulsar-client-cpp library.
* Link to OpenSSL statically when LINK_STATIC is ON ### Motivation See discussions here: #28 (comment) The original purpose to not include static OpenSSL library in `libpulsarwithnossl.so` and `libpulsarwithdeps.a` is apache/pulsar#6458. However, the ABI compatibility of OpenSSL is not good. If the Pulsar C++ library links dynamically to OpenSSL and the user only changes the OpenSSL dynamic library, some symbols might not be found. ### Modifications Use `LINK_STATIC` option to determine whether to link to OpenSSL library statically. After that, there are only 3 libraries generated when `LINK_STATIC` is ON. - `libpulsar.so`: the dynamic pulsar-client-cpp library. - `libpulsar.a`: the static pulsar-client-cpp library. When it's used, users must link to all 3rd party dependencies (OpenSSL, curl, etc.) - `libpulsarwithdeps.a`: the static pulsar-client-cpp library. * Remove unnecessary code * Remove libpulsarnossl.so build
Motivation
Currently, even with
LINK_STATIC=ONoption, dynamic libraries could still be linked. For example, on macOS, the following libcurl library will be found:Then, the
libpulsar.dylibwill link to/usr/lib/libcurl.4.dylib, which is not a static library.Modifications
When
LINK_STATICis enabled, changeCMAKE_FIND_LIBRARY_SUFFIXESto.afor non-MSVC compilers so that only static libraries could be found except OpenSSL, which should not be linked statically.In addition, use
find_packageas much as possible instead of raw usages offind_pathandfind_library.Documentation
doc-required(Your PR needs to update docs and you will update later)
doc-not-needed(Please explain why)
doc(Your PR contains doc changes)
doc-complete(Docs have been already added)