When cross-compiling, I am in the habit of using a toolchain file to specify (among other things) the CMAKE_SYSTEM_PROCESSOR
.
In Ubuntu and other Linux distros, it seems to be able to install libraries intended for other architectures. For example, if I am working on an x86-64 machine, and want to install libpng
for 64-bit ARM, then I would:
dpkg --add-architecture arm64
apt-get update
apt-get -y install libpng-dev:arm64
So after this, I have the libpng binaries for arm64. These seem to be installed in /usr/lib/aarch64-linux-gnu
.
Now my understanding is that if I try to find the libpng
in my CMakeLists.txt file (see CMake compile options for libpng ):
find_package(PNG REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
target_link_libraries(example ${PNG_LIBRARY})
it will find the packages for the host machine (in this case x86-64), and not the target (arm64).
Is there a way to tell Cmake's find_package
the target architecture? In the ideal case, find_package
would examine CMAKE_SYSTEM_PROCESSOR
before searching. I would like to know the easiest and most general way to handle this scenario since I am linking several libraries.
Right now the only method I am aware of is to hardcode the paths to the target libraries.
Modules like FindPNG.cmake use find_path
and find_library
to find all the things.
You can influence find_library
by setting CMAKE_LIBRARY_ARCHITECTURE
to aarch64-linux-gnu
. Try just setting CMAKE_LIBRARY_ARCHITECTURE
in your toolchain file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.