conan: [bug] conan 2.x: linking against a shared lib with private shared dependencies fails on Linux (again)

Environment details

  • Operating System+version: Ubuntu 22.04
  • Compiler+version: gcc 12.1.0
  • Conan version: 2.0.2
  • Python version: 3.10.6

Steps to reproduce

conan install --requires="libzippp/6.0-1.9.2" -o "*:shared=True" -b missing

Logs

build log
libzippp/6.0-1.9.2: Building from source
libzippp/6.0-1.9.2: Package libzippp/6.0-1.9.2:ee3488ab65102991abf5b636e39de538d8d3e7ab
libzippp/6.0-1.9.2: Copying sources to build folder
libzippp/6.0-1.9.2: Building your package in /home/spaceim/.conan2/p/t/libzic30b1ebec828d/b
libzippp/6.0-1.9.2: Calling generate()
libzippp/6.0-1.9.2: Generators folder: /home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/build/Release/generators
libzippp/6.0-1.9.2: CMakeToolchain generated: conan_toolchain.cmake
libzippp/6.0-1.9.2: CMakeToolchain generated: CMakePresets.json
libzippp/6.0-1.9.2: CMakeToolchain generated: ../../../src/CMakeUserPresets.json
libzippp/6.0-1.9.2: Generating aggregated env files
libzippp/6.0-1.9.2: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']
libzippp/6.0-1.9.2: Calling build()
libzippp/6.0-1.9.2: Running CMake.configure()
libzippp/6.0-1.9.2: RUN: cmake -G "Ninja" -DCMAKE_TOOLCHAIN_FILE="/home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/build/Release/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/home/spaceim/.conan2/p/t/libzic30b1ebec828d/p" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/src"
-- Using Conan toolchain: /home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/build/Release/generators/conan_toolchain.cmake
-- Conan toolchain: Setting BUILD_SHARED_LIBS = ON
-- The C compiler identification is GNU 12.1.0
-- The CXX compiler identification is GNU 12.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/gcc-12 - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/g++-12 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: Component target declared 'libzip::zip'
-- Conan: Target declared 'ZLIB::ZLIB'
-- Conan: Target declared 'BZip2::BZip2'
-- Conan: Including build module from '/home/spaceim/.conan2/p/bzip2b4101dd1d9e37/p/lib/cmake/conan-official-bzip2-variables.cmake'
-- Conan: Target declared 'LibLZMA::LibLZMA'
-- Conan: Including build module from '/home/spaceim/.conan2/p/xz_utae9210766e49b/p/lib/cmake/conan-official-xz_utils-variables.cmake'
-- Conan: Component target declared 'zstd::libzstd_shared'
-- Conan: Component target declared 'OpenSSL::Crypto'
-- Conan: Component target declared 'OpenSSL::SSL'
-- Conan: Target declared 'openssl::openssl'
-- Conan: Including build module from '/home/spaceim/.conan2/p/opens3b56123e737a3/p/lib/cmake/conan-official-openssl-variables.cmake'
-- Configuring done (5.2s)
-- Generating done (0.0s)
-- Build files have been written to: /home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/build/Release

libzippp/6.0-1.9.2: Running CMake.build()
libzippp/6.0-1.9.2: RUN: cmake --build "/home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/build/Release" -- -j8
[1/4] Building CXX object CMakeFiles/libzippp.dir/src/libzippp.cpp.o
/home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/src/src/libzippp.cpp: In function ‘void defaultErrorHandler(const std::string&, const std::string&, int, int)’:
/home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/src/src/libzippp.cpp:127:37: warning: unused parameter ‘zip_error_code’ [-Wunused-parameter]
  127 |                                 int zip_error_code,
      |                                 ~~~~^~~~~~~~~~~~~~
/home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/src/src/libzippp.cpp:128:37: warning: unused parameter ‘system_error_code’ [-Wunused-parameter]
  128 |                                 int system_error_code)
      |                                 ~~~~^~~~~~~~~~~~~~~~~
/home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/src/src/libzippp.cpp: In function ‘void progress_callback(zip*, double, void*)’:
/home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/src/src/libzippp.cpp:350:29: warning: unused parameter ‘archive’ [-Wunused-parameter]
  350 | void progress_callback(zip* archive, double progression, void* ud) {
      |                        ~~~~~^~~~~~~
/home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/src/src/libzippp.cpp: In function ‘int progress_cancel_callback(zip*, void*)’:
/home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/src/src/libzippp.cpp:359:35: warning: unused parameter ‘archive’ [-Wunused-parameter]
  359 | int progress_cancel_callback(zip *archive, void *ud) {
      |                              ~~~~~^~~~~~~
[3/4] Building CXX object CMakeFiles/libzippp_test.dir/tests/tests.cpp.o
/home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/src/tests/tests.cpp: In function ‘void test21()’:
/home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/src/tests/tests.cpp:678:45: warning: the address of ‘int fflush(FILE*)’ will never be NULL [-Waddress]
  678 |     cout << "Running test 21..." << endl << fflush;
      |                                             ^~~~~~
In file included from /usr/include/c++/12/cstdio:42,
                 from /usr/include/c++/12/ext/string_conversions.h:43,
                 from /usr/include/c++/12/bits/basic_string.h:3960,
                 from /usr/include/c++/12/string:53,
                 from /usr/include/c++/12/bits/locale_classes.h:40,
                 from /usr/include/c++/12/bits/ios_base.h:41,
                 from /usr/include/c++/12/ios:42,
                 from /usr/include/c++/12/ostream:38,
                 from /usr/include/c++/12/iostream:39,
                 from /home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/src/tests/tests.cpp:38:
/usr/include/stdio.h:230:12: note: ‘int fflush(FILE*)’ declared here
  230 | extern int fflush (FILE *__stream);
      |            ^~~~~~
/home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/src/tests/tests.cpp: In function ‘int main(int, char**)’:
/home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/src/tests/tests.cpp:895:14: warning: unused parameter ‘argc’ [-Wunused-parameter]
  895 | int main(int argc, char** argv) {
      |          ~~~~^~~~
/home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/src/tests/tests.cpp:895:27: warning: unused parameter ‘argv’ [-Wunused-parameter]
  895 | int main(int argc, char** argv) {
      |                    ~~~~~~~^~~~
[4/4] Linking CXX executable libzippp_shared_test
FAILED: libzippp_shared_test
: && /usr/bin/g++-12 -W -Wall -Wextra -ansi -pedantic -std=c++11 -O3 -m64 CMakeFiles/libzippp_test.dir/tests/tests.cpp.o -o libzippp_shared_test  -Wl,-rpath,/home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/build/Release  libzippp.so && :
/usr/bin/ld: warning: libcrypto.so.1.1, needed by /home/spaceim/.conan2/p/libzi1690beeedfbba/p/lib/libzip.so.5, not found (try using -rpath or -rpath-link)
/usr/bin/ld: /home/spaceim/.conan2/p/libzi1690beeedfbba/p/lib/libzip.so.5: undefined reference to `EVP_aes_128_ecb@OPENSSL_1_1_0'
/usr/bin/ld: /home/spaceim/.conan2/p/libzi1690beeedfbba/p/lib/libzip.so.5: undefined reference to `PKCS5_PBKDF2_HMAC_SHA1@OPENSSL_1_1_0'
/usr/bin/ld: /home/spaceim/.conan2/p/libzi1690beeedfbba/p/lib/libzip.so.5: undefined reference to `HMAC_CTX_new@OPENSSL_1_1_0'
/usr/bin/ld: /home/spaceim/.conan2/p/libzi1690beeedfbba/p/lib/libzip.so.5: undefined reference to `EVP_sha1@OPENSSL_1_1_0'
/usr/bin/ld: /home/spaceim/.conan2/p/libzi1690beeedfbba/p/lib/libzip.so.5: undefined reference to `HMAC_Final@OPENSSL_1_1_0'
/usr/bin/ld: /home/spaceim/.conan2/p/libzi1690beeedfbba/p/lib/libzip.so.5: undefined reference to `EVP_aes_192_ecb@OPENSSL_1_1_0'
/usr/bin/ld: /home/spaceim/.conan2/p/libzi1690beeedfbba/p/lib/libzip.so.5: undefined reference to `HMAC_Init_ex@OPENSSL_1_1_0'
/usr/bin/ld: /home/spaceim/.conan2/p/libzi1690beeedfbba/p/lib/libzip.so.5: undefined reference to `EVP_EncryptUpdate@OPENSSL_1_1_0'
/usr/bin/ld: /home/spaceim/.conan2/p/libzi1690beeedfbba/p/lib/libzip.so.5: undefined reference to `HMAC_CTX_free@OPENSSL_1_1_0'
/usr/bin/ld: /home/spaceim/.conan2/p/libzi1690beeedfbba/p/lib/libzip.so.5: undefined reference to `EVP_CIPHER_CTX_new@OPENSSL_1_1_0'
/usr/bin/ld: /home/spaceim/.conan2/p/libzi1690beeedfbba/p/lib/libzip.so.5: undefined reference to `EVP_EncryptInit_ex@OPENSSL_1_1_0'
/usr/bin/ld: /home/spaceim/.conan2/p/libzi1690beeedfbba/p/lib/libzip.so.5: undefined reference to `EVP_aes_256_ecb@OPENSSL_1_1_0'
/usr/bin/ld: /home/spaceim/.conan2/p/libzi1690beeedfbba/p/lib/libzip.so.5: undefined reference to `EVP_CIPHER_CTX_free@OPENSSL_1_1_0'
/usr/bin/ld: /home/spaceim/.conan2/p/libzi1690beeedfbba/p/lib/libzip.so.5: undefined reference to `RAND_bytes@OPENSSL_1_1_0'
/usr/bin/ld: /home/spaceim/.conan2/p/libzi1690beeedfbba/p/lib/libzip.so.5: undefined reference to `HMAC_Update@OPENSSL_1_1_0'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

libzippp/6.0-1.9.2: ERROR:
Package 'ee3488ab65102991abf5b636e39de538d8d3e7ab' build failed
libzippp/6.0-1.9.2: WARN: Build folder /home/spaceim/.conan2/p/t/libzic30b1ebec828d/b/build/Release
*********************************************************
Recipe 'libzippp/6.0-1.9.2' cannot build its binary
It is possible that this recipe is not Conan 2.0 ready
If the recipe comes from ConanCenter check: https://conan.io/cci-v2.html
If it is your recipe, check if it is updated to 2.0
*********************************************************

ERROR: libzippp/6.0-1.9.2: Error in build() method, line 88
        cmake.build()
        ConanException: Error 1 while executing

related to https://github.com/conan-io/conan/issues/13000

If you dig into libzippp recipe, recipe of its dependency libzip, their upstream CMakeLists and how they are patched, you’ll see that libzippp properly links to libzip::zip target defined in libzip recipe, and that openssl::crypto conan component of openssl recipe is properly appended to requires of this libzip::_libzip conan component in package_info() of libzip. Still, openssl crypto is missing in -rpath-link when linker tries to create libzippp shared lib.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20 (20 by maintainers)

Commits related to this issue

Most upvoted comments

I can confirm that the newer/still experimental CMakeDeps fixes this issue and we’ve managed to isolate and reproduce it.

Based on the original issue reported in the issue description:

Still, openssl crypto is missing in -rpath-link when linker tries to create libzippp shared lib.

This is a bit nuanced, the linker is not failing to a create the libzippp shared lib - the linker is failing to link the libzippp_shared_test executable within the libzippp project when creating the shared variant of the package.

This is due to this: https://github.com/ctabin/libzippp/blob/a570af1e3b11292567c9542d4f60bb3b15f037b3/CMakeLists.txt#L84-L92

At this point, the libzippp library target, is not a target created by CMakeDeps, so it doesn’t benefit from the earlier fix in https://github.com/conan-io/conan/pull/13010

Other instances of CMake not adding -rpath/-rpath-link when the target was generated by Conan… are actually different bugs altogether. But at least the one originally reported in this issue, I believe the newer CMakeDeps implementation fixes it. This is not a widespread issue in COnan Center because not all libraries build executables (as we typically disable tests, docs, etc).

The issue only happens when using the GNU bfd Linker (the default on most Linuxes) - if gold, lld or mold are used, this is unlikely to be a problem

Possible workarounds for “older” CMakeDeps:

  • Just have an rpath pointing to all host library directories - this should have little effect of negative consequences (the build rpath should not end up in the packaged library anyway)
        if self.settings.os == "Linux":
            libdirs_host = [l for dependency in self.dependencies.host.values() for l in dependency.cpp_info.aggregated_components().libdirs]
            tc.variables["CMAKE_BUILD_RPATH"] = ";".join(libdirs_host)
tools.build:exelinkflags=['-fuse-ld=bfd', '-Wl,--allow-shlib-undefined']

EIther way this should be preferred over tweaking any build scripts to use a public instead of private dependency.

The underlying cause is indeed a lack of the IMPORTED_LINK_DEPENDENT_LIBRARIES_ - we’re looking into implementing that in the new CMakeDeps, which should also take care of the issue when crossbuilding with a sysroot (in which case there should be -rpath-link instead of -rpath)