Hey,
Leading with this:
I’ve been able to successfully build the application on the TX2i but because we’re contractually obligated to provide cross-compiling support, I need to be able to cross-compile.
I’ve been trying to cross-compile an application for the TX2i using CMake and it always fails to link.
I’ve downloaded the latest cross-compile toolchain (GCC Tool Chain for 64-bit BSP) and unzipped it into my x86_64 machine’s /home/user/ directory.
Then I followed LinuxDev’s guide here to create a loopback copy of my TX2i files on the x86_64 machine.
Then I created these symbolic links:
/usr/lib/aarch64-linux-gnu → /usr/local/loopback_tx2i/usr/lib/aarch64-linux-gnu
/usr/include/aarch64-linux-gnu → /usr/local/loopback_tx2i/usr/include/aarch64-linux-gnu
I managed to cross-compile a simple hello_world program with this command:
cmake -D CMAKE_TOOLCHAIN_FILE=…/toolchain.cmake …
Here is the toolchain.cmake file:
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_LIBRARY_ARCHITECTURE aarch64-unknown-linux-gnu)set(CMAKE_SYSROOT /usr/local/loopback_tx2i)
set(CMAKE_C_COMPILER /home/user/install/bin/aarch64-unknown-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER /home/user/install/bin/aarch64-unknown-linux-gnu-g++)set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)set(CMAKE_TRY_COMPILE_TARGET_TYPE “STATIC_LIBRARY”)
I copied the executable over to my TX2i and it printed Hello World! as expected.
However, when I try to cross-compile my actual application with the same toolchain file, I get the following output.
Scanning dependencies of target [redacted]
[ 10%] Building CXX object src/CMakeFiles/[redacted].dir/[redacted].cpp.o
[ 20%] Building CXX object src/CMakeFiles/[redacted].dir/home/user/[redacted]/application/tcp_msgs/cpp_msgs/[redacted].pb.cc.o
[ 30%] Building CXX object src/CMakeFiles/[redacted].dir/home/user/[redacted]/application/tcp_msgs/cpp_msgs/[redacted].pb.cc.o
[ 40%] Building CXX object src/CMakeFiles/[redacted].dir/[redacted].cpp.o
[ 50%] Building CXX object src/CMakeFiles/[redacted].dir/I2CInterface.cpp.o
[ 60%] Linking CXX executable [redacted]
/home/user/install/bin/…/lib/gcc/aarch64-unknown-linux-gnu/4.8.5/…/…/…/…/aarch64-unknown-linux-gnu/bin/ld: warning: libz.so.1, needed by /usr/local/loopback_tx2i/usr/local/lib/libprotobuf.so, not found (try using -rpath or -rpath-link)
CMakeFiles/[redacted].dir/[redacted].cpp.o: In functionmain': [redacted].cpp:(.text+0x4cc): undefined reference togoogle::protobuf::MessageLite::SerializeAsString() const’
CMakeFiles/[redacted].dir/[redacted].cpp.o: In function `google::protobuf::internal::GetEmptyStringAlreadyInited()':[redacted].cpp:(.text._ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv[_ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv]+0x8):
undefined reference to ` google::protobuf::internal::fixed_address_empty_string’
…Nearly 100 more lines of linker errors…
I’m assuming my CMake toolchain file is just not pointing to the right libraries or I haven’t created enough symbolic links.
Any help is appreciated.
Thank you,
David