hyperrealm / libconfig

C/C++ library for processing configuration files
https://hyperrealm.github.io/libconfig/
GNU Lesser General Public License v2.1
1.1k stars 360 forks source link

Compiling fails when installed locally (cmake) #157

Open zyzzyxdonta opened 4 years ago

zyzzyxdonta commented 4 years ago

I include libconfig in my cmake project with find_package(libconfig++ REQUIRED) and target_link_libraries(${PROJECT_NAME} config++). Both on Archlinux and Fedora 31 this works fine. However on a remote machine to which I don't have root access, therefore only a local libconfig installation, linking fails with /usr/bin/ld: cannot find -lconfig++.

To install libconfig, I used the tarball from the project site, ran configure --prefix=$HOME/.local and make install and make test ran without a problem. Compiling my project works fine. I think the header files are found due to spdlog also being installed locally. When spdlog is not installed, the libconfig headers aren't found, either. So I guess there must be something wrong in the cmake configuration.

Printing all cmake variables shows:

...
-- CMAKE_SYSTEM_PREFIX_PATH=...;/home/<name>/.local;...
...
-- CONFIG_FILES=/home/<name>/.local/lib/cmake/spdlog/spdlogConfigTargets-release.cmake # no libconfig here
...
-- libconfig++_CONFIG=/home/<name>/.local/lib/cmake/libconfig++/libconfig++Config.cmake
-- libconfig++_CONSIDERED_CONFIGS=/home/<name>/.local/lib/cmake/libconfig++/libconfig++Config.cmake
-- libconfig++_CONSIDERED_VERSIONS=unknown
-- libconfig++_DIR=/home/<name>/.local/lib/cmake/libconfig++
-- libconfig++_FOUND=1
-- libconfig++_VERSION_COUNT=0
-- libconfig++_VERSION_MAJOR=0
-- libconfig++_VERSION_MINOR=0
-- libconfig++_VERSION_PATCH=0
-- libconfig++_VERSION_TWEAK=0

On further investigation, I found that in the file ~/.local/lib/cmake/libconfig++/libconfig++Config.cmake the prefix variables are not substituted in:

set(LIBCONFIG++_FOUND 1)
set(LIBCONFIG++_VERSION "1.7")
set(LIBCONFIG++_LIBRARIES "config++")
set(LIBCONFIG++_LIBRARY_DIRS "${exec_prefix}/lib")
set(LIBCONFIG++_LDFLAGS "")
set(LIBCONFIG++_INCLUDE_DIRS "${prefix}/include")
set(LIBCONFIG++_CFLAGS "")

Is this supposed to happen during runtime? Printing those out results in /lib and /include. In Fedora, on the other hand, the file itself has both prefixes already replaced with /usr/lib64. But then again, on Archlinux the file looks the same, the prefixes are not substituted in, either, and everything works fine.

autoreconf in libconfig fails with "none" is not exported by the List::Util module.

g++ (GCC) 9.1.0 cmake version 3.15.2

Edit: I didn't know I had to use the find script from the contrib directory. I assumed finding the library had worked since LIBCONFIG++_FOUND was set to 1. I now use pkg_check_modules to load the PkgConfig into cmake which works on any of my machines.