简体   繁体   中英

CMake cross compile

I'm having problem with my cmake cross compiler project.

My cross compiler did not find used libraries. I setup my cross compiler with this tutorial Cross Compiler .

Now i need libs they are installed on my RaspberryPi. I have snychronised my /lib and /usr direcotry from Pi to my Computer in /opt/cross/rasp. This is my Toolchain file:

# this one is important
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)

# specify the cross compiler
SET(CMAKE_C_COMPILER
/opt/cross/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc)

SET(CMAKE_CXX_COMPILER
/opt/cross/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-g++)

# where is the target environment
SET(CMAKE_FIND_ROOT_PATH /opt/cross/rasp)

# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

But when i try to compile my program i get following Linking Error:

/opt/cross/x-tools/arm-unknown-linux-gnueabi/lib/gcc/arm-unknown-linux-gnueabi/4.9.1/../../../../arm-unknown-linux-gnueabi/bin/ld: warning: libltdl.so.7, needed by /opt/cross/rasp/usr/local/lib/libgphoto2.so, not found (try using -rpath or -rpath-link)
/opt/cross/x-tools/arm-unknown-linux-gnueabi/lib/gcc/arm-unknown-linux-gnueabi/4.9.1/../../../../arm-unknown-linux-gnueabi/bin/ld: warning: libexif.so.12, needed by /opt/cross/rasp/usr/local/lib/libgphoto2.so, not found (try using -rpath or -rpath-link)

On my RaspberrPi is compiling without errors possible.

The problem seems link to a misinterpretation of etc/ld.so.conf see fixing-rpath-link-issues-with-cross-compilers

In order to add the missing rpath-link, you can append to the toolchain cmake file :

SET(CMAKE_EXE_LINKER_FLAGS "-Wl,-rpath-link=/opt/cross/rasp/lib/arm-linux-gnueabihf:/opt/cross/rasp/usr/lib/arm-linux-gnueabihf")

I believe your cross-compile linker needs a --sysroot change. In the toolchain file you can use:

set(CMAKE_SYSROOT "/opt/cross/rasp")

Should anyone be looking for another reference, aside from the original question, I recommend reading through the ARM cross-compile guide from Takeoff Technical:

https://takeofftechnical.com/x-compile-cpp-bbb

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM