How to specify architecture in CMakeLists?

asked 2017-02-07 20:48:06 -0600

Cerin gravatar image

updated 2017-02-07 20:56:21 -0600

I'm attempting to cross-compile some code for a Raspberry Pi on my Amd64 laptop. My manually installing the Raspberry Pi firmware headers, I've been able to get my code to compile, but catkin_make still fails when it tries to link my objects to some shared dependencies.

####
#### Running command: "make -j4 -l4" in "/tmp/raspicam_node_test/catkin_ws/build"
####
Scanning dependencies of target raspicam_node
Scanning dependencies of target raspicam_raw_node
[ 25%] Building CXX object raspicam/CMakeFiles/raspicam_node.dir/src/raspicam_node.cpp.o
[ 50%] Building CXX object raspicam/CMakeFiles/raspicam_raw_node.dir/src/raspicam_raw_node.cpp.o
[ 75%] Linking CXX executable /tmp/raspicam_node_test/catkin_ws/devel/lib/raspicam/raspicam_raw_node
[100%] Linking CXX executable /tmp/raspicam_node_test/catkin_ws/devel/lib/raspicam/raspicam_node
/opt/vc/lib/libbcm_host.so: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
/opt/vc/lib/libbcm_host.so: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
raspicam/CMakeFiles/raspicam_raw_node.dir/build.make:174: recipe for target '/tmp/raspicam_node_test/catkin_ws/devel/lib/raspicam/raspicam_raw_node' failed
make[2]: *** [/tmp/raspicam_node_test/catkin_ws/devel/lib/raspicam/raspicam_raw_node] Error 1
raspicam/CMakeFiles/raspicam_node.dir/build.make:174: recipe for target '/tmp/raspicam_node_test/catkin_ws/devel/lib/raspicam/raspicam_node' failed
make[2]: *** [/tmp/raspicam_node_test/catkin_ws/devel/lib/raspicam/raspicam_node] Error 1
CMakeFiles/Makefile2:362: recipe for target 'raspicam/CMakeFiles/raspicam_raw_node.dir/all' failed
make[1]: *** [raspicam/CMakeFiles/raspicam_raw_node.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
CMakeFiles/Makefile2:783: recipe for target 'raspicam/CMakeFiles/raspicam_node.dir/all' failed
make[1]: *** [raspicam/CMakeFiles/raspicam_node.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j4 -l4" failed

I'm assuming this is because the *.so objects in my /opt/vc/lib directory are compiled for ARM whereas my makefile is compiling for Amd64? How do I specify architecture in CMakeLists to tell it to compile for ARM?

If I add these to my CMakeLists to instruct it to use an ARM compiler:

set(CMAKE_CXX_COMPILER "arm-linux-gnueabihf-g++")
set(CFLAGS "-mfloat -abi=hard")

that fixes the link errors against /opt/vc/lib, but now it creates new link errors against /opt/ros/kinetic/lib/libcompressed_image_transport.so, again, presumably because it's in Amd64 format and not ARM.

So it looks like I'm stuck. What's the appropriate way to cross-compile an ARM ROS node on an Amd64 platform?

edit retag flag offensive close merge delete