cmake fails to link SDBusCpp::sdbus-c++
Closed this issue · 2 comments
Describe the bug
CMake Generate step fails when adding SDBusCpp::sdbus-c++ to target_link_libraries in project CMakeLists.txt,
To Reproduce
Environment: Windows 11 WSL Ubuntu 24.04.1 LTS
cmake version 3.28.3
ninja version1.11.1
vcpkg package management program version 2024-10-18-e392d7347fe72dff56e7857f7571c22301237ae6
pkg-config version 1.8.1
vcpkg list
azure-core-cpp:x64-linux 1.14.0#1 Microsoft Azure Core SDK for C++
azure-core-cpp[curl]:x64-linux Libcurl HTTP transport implementation
azure-core-cpp[http]:x64-linux All HTTP transport implementations available on ...
azure-identity-cpp:x64-linux 1.10.0#2 Microsoft Azure Identity SDK for C++
azure-storage-blobs-cpp:x64-linux 12.13.0#1 Microsoft Azure Storage Blobs SDK for C++
azure-storage-common-cpp:x64-linux 12.8.0#1 Microsoft Azure Common Storage SDK for C++
curl:x64-linux 8.10.1#2 A library for transferring data with URLs
curl[non-http]:x64-linux Enables protocols beyond HTTP/HTTPS/HTTP2
curl[openssl]:x64-linux SSL support (OpenSSL)
curl[ssl]:x64-linux Default SSL backend
dbus:x64-linux 1.15.8#5 D-Bus specification and reference implementation...
dbus[systemd]:x64-linux Build with systemd at_console support
expat:x64-linux 2.6.3 XML parser library written in C
gperf:x64-linux 3.1#6 GNU perfect hash function generator
libcap:x64-linux 2.70 A library for getting and setting POSIX.1e (form...
libiconv:x64-linux 1.17#4 GNU Unicode text conversion
liblzma:x64-linux 5.6.3 Compression library with an API similar to that ...
libmount:x64-linux 2.40 Block device identification library from util-linux
libsystemd:x64-linux 256.4 Libsystemd
libxcrypt:x64-linux 4.4.36#1 libxcrypt is a modern library for one-way hashin...
libxml2:x64-linux 2.11.9 Libxml2 is the XML C parser and toolkit develope...
libxml2[iconv]:x64-linux Add ICONV support
libxml2[lzma]:x64-linux Use LZMA
libxml2[zlib]:x64-linux Use ZLib
lz4:x64-linux 1.10.0 Lossless compression algorithm, providing compre...
openssl:x64-linux 3.4.0 OpenSSL is an open source project that provides ...
pkgconf:x64-linux 2.3.0 pkgconf is a program which helps to configure co...
sdbus-cpp:x64-linux 2.0.0 High-level C++ D-Bus library for Linux designed ...
vcpkg-cmake-config:x64-linux 2024-05-23
vcpkg-cmake-get-vars:x64-linux 2024-09-22
vcpkg-cmake:x64-linux 2024-04-23
vcpkg-tool-meson:x64-linux 1.6.0 Meson build system
zlib:x64-linux 1.3.1 A compression library
zstd:x64-linux 1.5.6 Zstandard - Fast real-time compression algorithm
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
set(CMAKE_TOOLCHAIN_FILE="${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
project(paketarchiver)
include_directories(src)
include_directories(${PCAP_INCLUDE_DIRS})
link_directories(${PCAP_LIBRARY_DIRS})
find_package(PkgConfig REQUIRED)
find_package(azure-storage-blobs-cpp CONFIG REQUIRED)
find_package(sdbus-c++ REQUIRED)
add_executable(parc src/main.cpp src/client.cpp src/packet.cpp src/storage.cpp)
target_link_libraries(parc PRIVATE ${PCAP_LIBRARIES} ${nlohmann_json_LIBRARIES} Azure::azure-storage-blobs SDBusCpp::sdbus-c++)
Expected behavior
The build works.
Real (buggy) behavior
CMake Error at build/vcpkg_installed/x64-linux/share/sdbus-c++/sdbus-c++-targets.cmake:68 (set_target_properties):
The link interface of target "SDBusCpp::sdbus-c++-objlib" contains:
PkgConfig::Systemd
but the target was not found. Possible reasons include:
* There is a typo in the target name.
* A find_package call is missing for an IMPORTED target.
* An ALIAS target is missing.
Call Stack (most recent call first):
build/vcpkg_installed/x64-linux/share/sdbus-c++/sdbus-c++-config.cmake:27 (include)
/home/dguise/dev/vcpkg/scripts/buildsystems/vcpkg.cmake:859 (_find_package)
CMakeLists.txt:12 (find_package)
Additional context
I'm new to cmake and vcpkg but have been building the app prior to trying to add sdbus-c++. Have tried different variations in CMakeLists.txt such as:
target_link_libraries(parc PRIVATE ${PCAP_LIBRARIES} ${nlohmann_json_LIBRARIES} Azure::azure-storage-blobs ${sdbus-c++_LIBRARIES})
/usr/bin/ld: cannot find -lcap: No such file or directory
/usr/bin/ld: cannot find -llz4: No such file or directory
/usr/bin/ld: cannot find -llzma: No such file or directory
/usr/bin/ld: cannot find -lzstd: No such file or directory
/usr/bin/ld: cannot find -lmount: No such file or directory
/usr/bin/ld: cannot find -lblkid: No such file or directory
target_link_libraries(parc PRIVATE ${PCAP_LIBRARIES} ${nlohmann_json_LIBRARIES} Azure::azure-storage-blobs ${sdbus-cpp_LIBRARIES})
produces a bunch of undefined references like: undefined reference to `sdbus::createProxy(sdbus::BusName, sdbus::ObjectPath)'
It looks like you have sdbus-c++ installed as a static library. The standard is sdbus-c++ as a shared library... If you use vcpkg
to install sdbus-c++, the question is why they ship sdbus-c++ as a static library and whether there is a way to ship it as a shared one.
Then, it looks like libsystemd is also built and installed as a static library. Again, why isn't it distributed as a shared lib? This is very non-standard. Static libs bring a lot of issues, like additional linking dependencies, leading to problems like you've got with pcap, lzma, mount, etc.
Btw., does adding this to your CMakeLists.txt before find_package(sdbus-c++)
help you?
find_package(PkgConfig REQUIRED)
pkg_check_modules(Systemd IMPORTED_TARGET GLOBAL libsystemd>=239)
What output do you get after that?
I didn't find any libpcap for vcpkg so that's the reason for using the system lib. Haven't had any problems with libpcap; it links and runs fine, but did need to install libpcap-dev on the system.
Yes, I used vcpkg to install sdbus-c++ which includes libsystemd. The vcpkg list output shows systemd is 256.4 so I assumed that was good. Added the pkg_check_modules you suggested and that did the trick! The build now completes. The first cmake after the addition produced this:
-- Checking for module 'libsystemd>=239'
-- Found libsystemd, version 256
Apparently it was using another libsystemd... Much appreciated!