I’m creating a toolchain for cross-compiling on x64 for an ARM64 device.
I find some libraries using PkgConfig in the actual application and in the final linking command they’re linked like -lglib-2.0. Unfortunately this results in cannot find -lglib-2.0 despite the ARM64 variants existing under /usr/lib/aarch64-linux-gnu.
What would be the correct way to get CMake to add /usr/lib/aarch64-linux-gnu as a link directory on the command line?
Concerning the use of pkg-config it may be that the .pc file used is either the one from the host and/or it does not give enough information about link directory.
You could try cross-configure the following dummy project and observe outputed values:
note that you may need to help pkg-config to tell apart host vs target https://autotools.io/pkgconfig/cross-compiling.html in order to make pkg-config use proper system root.
You can specify CMAKE_SYSROOT in your toolchain too but I don’t know if it is automatically used by the FindPkgConfig module.
# cmake ../var_test/ -GNinja -DCMAKE_TOOLCHAIN_FILE=<REDACTED>
-- The CXX compiler identification is GNU 7.3.1
-- Check for working CXX compiler: <REDACTED>../toolchains/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++
-- Check for working CXX compiler: <REDACTED>../toolchains/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
--
Properties for DIRECTORY .:
..LINK_DIRECTORIES = "/usr/lib/aarch64-linux-gnu;/usr/lib/aarch64-linux-gnu"
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for one of the modules 'glib-2.0'
-- GLIB2_LIBRARY_DIRS="" ; GLIB2_LIBDIR="/usr/lib/x86_64-linux-gnu"
--
Properties for TARGET PkgConfig::GLIB2:
PkgConfig::GLIB2.INTERFACE_COMPILE_OPTIONS = <NOTFOUND>
PkgConfig::GLIB2.INTERFACE_LINK_DEPENDS = <NOTFOUND>
PkgConfig::GLIB2.INTERFACE_LINK_DIRECTORIES = <NOTFOUND>
PkgConfig::GLIB2.INTERFACE_LINK_LIBRARIES = <NOTFOUND>
PkgConfig::GLIB2.INTERFACE_LINK_OPTIONS = <NOTFOUND>
-- Configuring done
-- Generating done
-- Build files have been written to: /opt/build
Eric, thank you very much for the help!
The reason I don’t set CMAKE_SYSROOT is that the targetfs available on the host system is provided by the hardware vendor and doesn’t have some of the libraries I need to link to (but which are available on the actual system). As far as I understand, setting the sysroot would hinder me from linking to multiarch libraries in /usr/lib/aarch64-linux-gnu.
The include_directories()link_directories() unfortunately doesn’t seem to add the directories to the final link command. FindPkgConfiguses the architecture-appropriate pkgconfig file, but only when not cross-compiling, which I am.
It seems like it should be fairly easy for me to create a custom sysroot that also includes the ARM64 libraries I need on top of the vendor’s. I’ll give that go.
– Found PkgConfig: /usr/bin/pkg-config (found version “0.29.1”)
– Checking for one of the modules ‘glib-2.0’
– GLIB2_LIBRARY_DIRS=“” ; GLIB2_LIBDIR=“/usr/lib/x86_64-linux-gnu”
That’s the toolchain I’ve now ended up with and that works.
Creating my own sysroot was much easier than I thought and simplified the toolchain.
I appreciate everyone’s responses and help!
doesn’t work. The directories simply aren’t added to the final linking command. Why?
Being able to do the former would simplify the toolchain (as long as it also adds them to the rpath).