ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

How to know which version of gcc/g++ compiled ros and how to change it for compiling my workspace

asked 2019-02-04 03:59:02 -0600

ipgvl gravatar image

updated 2019-02-04 09:14:14 -0600

Hi,

I have a problem compiling my workspace: https://answers.ros.org/question/313955/undefined-reference-to-everything/ and I think that this could be because of the version of gcc and g++. I want to follow this answer: https://answers.ros.org/question/291910/linking-problem-with-catkin_libraries/ because I noticed that all of my undefined references involve std::string, like he said. But I don't know how to know if this is the problem or not, I don't know how to know which version of gcc/g++ was used to build ros and I don't know how to choose the version to compile my workspace (use the default compiler like the answer said).

Thank you in advance.

EDIT

Here the output of:

which gcc
/usr/bin/gcc

env | grep -E 'CC|CXX'
QT_LINUX_ACCESSIBILITY_ALWAYS_ON=1
QT_ACCESSIBILITY=1


gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2019-02-04 06:05:32 -0600

gvdhoorn gravatar image

updated 2019-02-04 07:50:58 -0600

"ROS" (in quotes as it's really ambiguous to ask these sort of things like that) is built with whatever is the default C++ compiler is on the system that it is built on.

In the end it's all CMake, so whatever CMake decides should be the compiler, will be the compiler.

You can override/configure that using the traditional CC and CXX environment variables (and using something called a toolchain file, but I'll ignore those here).


For ROS Kinetic on Ubuntu Xenial (16.04, amd64), the ROS buildfarm uses GCC version 5.4.0 -- as that is the default compiler on that platform. See the build output from this job (roscpp_core) fi:

11:22:56 -- The C compiler identification is GNU 5.4.0
11:22:56 -- The CXX compiler identification is GNU 5.4.0

This also tells you the path to the compiler binaries used:

11:22:56 -- Check for working C compiler: /usr/bin/cc
11:22:56 -- Check for working C compiler: /usr/bin/cc -- works
[..]
11:22:56 -- Check for working CXX compiler: /usr/bin/c++
11:22:56 -- Check for working CXX compiler: /usr/bin/c++ -- works

You can see the same output in a local invocation of catkin_make on ROS Kinetic/Ubuntu Xenial:

-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
[..]
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works

With catkin_tools you can see this by adding the -v option to your build verb invocation.

I don't know how to choose the version to compile my workspace (use the default compiler like the answer said).

It would probably be good to figure out what the currently used version is first. You can do that by checking the output of the various build commands and/or by running gcc --version.


Edit:

Since I wrote the question I uninstalled and reinstalled gcc and g++,

which version? And how did you "uninstall and reinstall" it?

and I used these commands too export CC=/usr/local/bin/gcc; export CXX=/usr/local/bin/g++.

Setting environment variables like that should not be necessary, unless you have a setup with special requirements.

Also: on Ubuntu, system-managed compilers (or at least: their symlinks) are typically found in /usr/bin. Are you sure your compiler is located in /usr/local? If that is the case, then you're most likely not using a system managed compiler, which may the reason why you run into these issues.

What is the output of /usr/local/bin/gcc --version?

And would you know how that compiler ended up there?

Then I used CXX=g++5 CC=gcc5 catkin_make and it worked but just for one of my packages.

I'm not sure why you'd still need to do that if you've ... (more)

edit flag offensive delete link more

Comments

@gvdhoorn Thank you for your reply. Since I wrote the question I uninstalled and reinstalled gcc and g++, and I used these commands too export CC=/usr/local/bin/gcc export CXX=/usr/local/bin/g++. Then I used CXX=g++5 CC=gcc5 catkin_make and it worked but just for one of my packages.

ipgvl gravatar image ipgvl  ( 2019-02-04 07:45:51 -0600 )edit

Running gcc --version and g++ --version give me 5.4.0 for both now. I suppose it was what you refer with "using the traditional CC and CXX variables", so I'm marking your answer.

ipgvl gravatar image ipgvl  ( 2019-02-04 07:52:44 -0600 )edit

With a simple setup (as I believe you have) you shouldn't need to touch any of that.

Did you just run gcc --version? What about the /usr/local/bin/gcc path that you showed earlier in your export CC=.. command? How does that relate to all this?

gvdhoorn gravatar image gvdhoorn  ( 2019-02-04 07:54:02 -0600 )edit

And as always when changing build environments: delete the devel and build folders from your workspace. Otherwise CMake will use cached values.

Open a clean terminal, make sure no CC or CXX is set, remove build and devel, source the normal /opt/ros/kinetic/setup.bash and ..

gvdhoorn gravatar image gvdhoorn  ( 2019-02-04 07:54:41 -0600 )edit

@gvdhoorn But I don't understand anything, because now my code runs but a simple listener doesn't and gives me the same "undefined reference" errors. If you know something about what the problem could be I would appreciate the info. And thank you again!

ipgvl gravatar image ipgvl  ( 2019-02-04 07:55:20 -0600 )edit

.. try to run catkin_make again.

Pay special attention to the output at the start of the process, where it tells you which compilers it's going to use.

gvdhoorn gravatar image gvdhoorn  ( 2019-02-04 07:56:09 -0600 )edit

If you know something about what the problem could be I would appreciate the info

let's stick to this problem for now.

Please answer all my questions.

I cannot help you if you don't respond to all of it.

gvdhoorn gravatar image gvdhoorn  ( 2019-02-04 07:57:00 -0600 )edit

@gvdhoorn Yes, sorry, I was already writing that comment when you wrote the answer, so I didn't see it. The key was to delete the devel and buil folders, because the listener had been built before the g++ changes but not the other. Thank you so much, it works now.

ipgvl gravatar image ipgvl  ( 2019-02-04 08:01:22 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2019-02-04 03:59:02 -0600

Seen: 8,033 times

Last updated: Feb 04 '19