Ask Your Question
2

Run catkin make with custom compiler

asked 2013-02-26 16:27:12 -0600

Noldorin gravatar image

I have tried exporting the CC, CXX, CMAKE_CXX_COMPILER env variables before running ./src/catkin/bin/catkin_make_isolated --install, but no luck. It still insists on using clang on OS X (10.8.2) for some reason. How can I tell it to use gcc instead?

edit retag flag offensive close merge delete

Comments

Just curious - is this to get around the bug in clang that prevents PCL from building?

Dan Lazewatsky gravatar imageDan Lazewatsky ( 2013-02-27 06:51:58 -0600 )edit

@Dan Lazewatsky: Indeed it is. I'm thinking building the whole thing with the gcc kit (or at least PCL and friends) will be the easy way!

Noldorin gravatar imageNoldorin ( 2013-02-27 06:54:52 -0600 )edit

Awesome. I'm excited to see how it work out!

Dan Lazewatsky gravatar imageDan Lazewatsky ( 2013-02-27 07:11:49 -0600 )edit

Sure, will let you know. ;)

Noldorin gravatar imageNoldorin ( 2013-02-27 10:29:07 -0600 )edit

@Dan Lazewatsky: Okay, there seems to be problems with the generators! They're returnin HTTP 500 errors now (desktop and desktop-full rather).

Noldorin gravatar imageNoldorin ( 2013-02-27 11:05:34 -0600 )edit

4 Answers

Sort by » oldest newest most voted
2

answered 2013-02-27 06:48:05 -0600

William gravatar image

You can pass them in as CMake variables:

./src/catkin/bin/catkin_make_isolated --install -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/gcc -v

This should make each of the run with the C/CXX compiler changed:

==> cmake /Users/william/ros_catkin_ws/src/catkin -DCATKIN_DEVEL_PREFIX=/Users/william/ros_catkin_ws/devel_isolated/catkin -DCMAKE_INSTALL_PREFIX=/Users/william/ros_catkin_ws/install_isolated -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/gcc
-- The C compiler identification is GNU 4.2.1
-- The CXX compiler identification is GNU 4.2.1
edit flag offensive delete link more

Comments

This works if I pass the parameters to cmake directly, but not catkin_make_isolated unfortunately! Catkin is really causing a lot of trouble, I have no idea what it's good for even... surely a build script that just loops through each directory in src/ and runs CMake would be superior as a solution?

Noldorin gravatar imageNoldorin ( 2013-02-28 05:05:37 -0600 )edit

That's what catkin_make_isolated does... There is no reason (other than maybe a bug) for why passing CMake arguments to CMake directly would work but not for CMI...

William gravatar imageWilliam ( 2013-02-28 05:30:23 -0600 )edit

It's pretty clear exactly which commands CMI is running, and if one fails it even tells you exactly how to reproduce that error without CMI. You can always build pcl_msgs manually, install it, build pcl manually, install it, remove them from the workspace, then try again.

William gravatar imageWilliam ( 2013-02-28 05:45:07 -0600 )edit

@William: Ah, well it seems that it works okay if I set environment variables, but whenever I pass the D options it always fails in the infinite loop (either directly via cmake or via catkin_make_isolated).

Noldorin gravatar imageNoldorin ( 2013-02-28 11:39:25 -0600 )edit
3

answered 2014-04-22 16:41:10 -0600

stefanct gravatar image

updated 2014-06-17 14:14:55 -0600

I found the most easy way to change the compiler CMake uses, is by adding the following to the respective CMakeList.txt file:

set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_C_COMPILER "clang")
edit flag offensive delete link more

Comments

Actually the path to the executable should be absolute:

set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
set(CMAKE_C_COMPILER "/usr/bin/clang")
li9i gravatar imageli9i ( 2019-09-26 05:16:08 -0600 )edit
1

answered 2014-04-23 17:19:11 -0600

Have you tried using a toolchain.cmake file?

Here is an example (for cross-compiling to the raspberry pi), I set the arm cross compiler:

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER arm-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER arm-linux-gnueabi-g++-4.4)
set(CMAKE_FIND_ROOT_PATH $ENV{HOME}/rpi/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/arm-bcm2708-linux-gnueabi/sysroot $ENV{HOME}/rpi/rootfs $ENV{HOME}/rpi/rootfs/e2fsprogs-1.42.9 $ENV{HOME}/rpi/rootfs/usr $ENV{HOME}/rpi/rootfs/usr/lib $ENV{HOME}/rpi/rootfs/usr/include $ENV{HOME}/rpi/ros_catkin_ws/install_isolated)
#SET( CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -mfpu=vfp -mfloat-abi=softfp -mcpu=arm1176jzf-s" )
#SET( CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} -static" )
# Have to set this one to BOTH, to allow CMake to find python
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Then, I invoke it with:

catkin_make_isolated --cmake-args -DCMAKE_TOOLCHAIN_FILE=/home/myuser/rpi/toolchain.raspi.cmake
edit flag offensive delete link more

Comments

This should be the correct answer. Using a toolchain file is the canonical way to do this with cmake.

strike_eagle_iii gravatar imagestrike_eagle_iii ( 2018-11-20 22:01:02 -0600 )edit
0

answered 2014-04-23 04:23:05 -0600

Nap gravatar image

I'm trying to do it in a similar way to Stefanct, but it doesn't work for me. So far, only the command line option works, as per how William described it.
By the time catkin_make gets to the set command in my CMakeList.txt file, its already chosen to use /usr/bin/cc and /usr/bin/c++ and gives an error c++: error: unrecognized command line option ‘-stdlib=libc++’ when I try to perform set(CMAKE_CXX_FLAGS "-v -std=c++11 -stdlib=libc++").
I set the flag in a slightly different way; by checking if clang is available before setting it.

find_program(CLANGPP clang++ HINTS /usr/local/bin /usr/bin /opt/local/bin)
if(${CLANGPP} MATCHES "clang")
set(CXX ${CLANGPP})
set(MAKE_CXX_COMPILER ${CLANGPP})
message(STATUS "CXX = ${CXX}")
endif(${CLANGPP} MATCHES "clang")

and the same for 'clang'.

I'm still trying different things, and when I get it working, I'll come back.

@stefanct, where in your CMakeList.txt file do you put those lines? Do you have an initialisation function?

edit flag offensive delete link more

Comments

I guess you are missing the 'C' at the beginning of CMAKE_CXX_COMPILER?

stefanct gravatar imagestefanct ( 2014-04-23 05:01:41 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2013-02-26 16:27:12 -0600

Seen: 8,099 times

Last updated: Jun 17 '14