1

I'm trying to build simple shared library for gazebo tutorials. In their website, CMakeLists file should be like this

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
find_package(gazebo REQUIRED)
include_directories(${GAZEBO_INCLUDE_DIRS})
link_directories(${GAZEBO_LIBRARY_DIRS})
list(APPEND CMAKE_CXX_FLAGS "${GAZEBO_CXX_FLAGS}")
add_library(hello_world SHARED hello_world.cc)
target_link_libraries(hello_world ${GAZEBO_LIBRARIES})

And They clearly mention the following

New in gazebo6: c++11 flags are now required for all downstream software to compile against gazebo. This is done with the following line: set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GAZEBO_CXX_FLAGS}")

Adding the preceding line in the above CMakeLists yields this error:

c++: fatal error: no input files
compilation terminated. 
/bin/sh: 1: -std=c++11: not found

Removing the line, the compilation proceeds without problem. Any suggestions? My machine:

Ubuntu 20.04.2 LTS, 
cmake version 3.16.3, 
g++ 9.3
CroCo
  • 5,531
  • 9
  • 56
  • 88
  • C++11 mode (or higher) have been default since GCC version 6. That specific flag for that specific C++ standard version isn't needed since a few years back. – Some programmer dude Mar 28 '21 at 06:19
  • 1
    As for how to solve your problem, I suggest you start by doing a verbose build to see exactly what commands are executed, and all options and flags are passed to each command.If you build with `make` then just enable it with `make VERBOSE=1`. – Some programmer dude Mar 28 '21 at 06:21
  • Read the documentation of [GCC](http://gcc.gnu.org/) – Basile Starynkevitch Mar 28 '21 at 06:23
  • 1
    You can't use `list(APPEND` for `CMAKE_CXX_FLAGS`, it puts semicolons in the string which end up starting new commands – Alan Birtles Mar 28 '21 at 07:08
  • Does the linked question answer the question? It seems like there is a newline in the GAZEBO_CXX_FLAGS judging from the error output. – Lasersköld Mar 28 '21 at 07:14
  • No, the command is likely something like `c++; -std=c++11 foo.cpp` two separate commands, no files passed to gcc then a second command starting with `-std` – Alan Birtles Mar 28 '21 at 07:16

0 Answers0