From f28a1c87e009acc28ff3e2bb6b0762b4e273a5da Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Tue, 27 Dec 2022 01:06:05 +0800 Subject: [PATCH] [fix][build] Hide non-exported symbols from the dependencies (#155) ### Motivation Currently the released libraries don't hide the symbols from the dependencies, it can be verified by the following steps on Ubuntu: ```bash curl -O -L https://archive.apache.org/dist/pulsar/pulsar-client-cpp-3.1.0/deb-x86_64/apache-pulsar-client.deb apt install ./apache-pulsar-client.deb nm -D /usr/lib/libpulsar.so | grep curl ``` You will see lots of symbols from libcurl are included in `libpulsar.so`: ``` 0000000000709f50 T curl_easy_cleanup 000000000070a000 T curl_easy_duphandle ... ``` The root cause is that `-Wl,--exclude-libs,ALL` is added as the compile option, but it should work as a link option. ### Modifications Use `add_link_options` to add `-Wl,--exclude-libs=ALL` as the link option. It seems that `=ALL` should be correct but `,ALL` also works. (cherry picked from commit 3a3e9739010944dd0bc09c45ba3e37d67427b21a) --- CMakeLists.txt | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bbad70fc..2492f653 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ # under the License. # -cmake_minimum_required(VERSION 3.4) +cmake_minimum_required(VERSION 3.13) project (pulsar-cpp) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake_modules") @@ -290,7 +290,7 @@ if (NOT APPLE AND NOT MSVC) # Hide all non-exported symbols to avoid conflicts add_compile_options(-fvisibility=hidden) if (CMAKE_COMPILER_IS_GNUCC) - add_compile_options(-Wl,--exclude-libs,ALL) + add_link_options(-Wl,--exclude-libs=ALL) endif () endif () diff --git a/README.md b/README.md index 33df78a7..648a1843 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Pulsar C++ client uses [doxygen](https://www.doxygen.nl) to build API documents. ## Requirements * A C++ compiler that supports C++11, like GCC >= 4.8 -* CMake >= 3.4 +* CMake >= 3.13 * [Boost](http://www.boost.org/) * [Protocol Buffer](https://developers.google.com/protocol-buffers/) >= 3 * [libcurl](https://curl.se/libcurl/)