Error when compiling with C++ 11 flags [solution found]

The engine.
Post Reply
HermanTheHumane
Posts: 1
Joined: Mon Mar 02, 2015 1:56 pm

Error when compiling with C++ 11 flags [solution found]

Post by HermanTheHumane »

Hi there,

I'm trying to compile a program using SMILE on Linux x64 but get this error:

"/include/smile/general.h:29:71: error: call of overloaded ‘isnan(double&)’ is ambiguous"

This even happens in the most simple program where nothing is being done except #include "smile.h".

However, this problem only occurs if I set CMAKE_CXX_FLAGS "-std=c++11 -O3" . If I dont use those flags, everything runs just fine.

Sample program used:

Code: Select all

#include "ros/ros.h"		// This is the Robot Operating System (ROS) framework, www.ros.org .
#include "../include/smile/smile.h"

int main(int argc, char **argv)
{
  std::cout << "Test" << std::endl;
  return 0;
}
Environment:
c++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2

Full compile error message (Eclipse Luna 4.4.1):

Code: Select all

[100%] Building CXX object CMakeFiles/programname_node.dir/src/programname_node.cc.o
/usr/bin/c++   -DROSCONSOLE_BACKEND_LOG4CXX -DROS_PACKAGE_NAME=\"ros_programname\" -std=c++11 -O3 -gdwarf-3 -I/opt/ros/indigo/include -I/home/humane/catkin_ws/src/ros_programname/include/smile -I/home/humane/catkin_ws/src/ros_programname/include    -o CMakeFiles/programname_node.dir/src/programname_node.cc.o -c /home/humane/catkin_ws/src/ros_programname/src/programname_node.cc
In file included from /home/humane/catkin_ws/src/ros_programname/src/../include/smile/dslobject.h:7:0,
                 from /home/humane/catkin_ws/src/ros_programname/src/../include/smile/syscoord.h:6,
                 from /home/humane/catkin_ws/src/ros_programname/src/../include/smile/smile.h:36,
                 from /home/humane/catkin_ws/src/ros_programname/src/programname_node.cc:11:
/home/humane/catkin_ws/src/ros_programname/src/../include/smile/general.h: In function ‘bool DSL_isnan(double)’:
/home/humane/catkin_ws/src/ros_programname/src/../include/smile/general.h:29:71: error: call of overloaded ‘isnan(double&)’ is ambiguous
  inline bool DSL_isnan(double x) { using namespace std; return isnan(x) != 0; }
                                                                       ^
/home/humane/catkin_ws/src/ros_programname/src/../include/smile/general.h:29:71: note: candidates are:
In file included from /usr/include/features.h:374:0,
                 from /usr/include/x86_64-linux-gnu/c++/4.8/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/4.8/bits/c++config.h:426,
                 from /usr/include/c++/4.8/iosfwd:38,
                 from /usr/include/c++/4.8/ios:38,
                 from /usr/include/c++/4.8/istream:38,
                 from /usr/include/c++/4.8/fstream:38,
                 from /home/humane/catkin_ws/src/ros_programname/src/programname_node.cc:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:234:1: note: int isnan(double)
 __MATHDECL_1 (int,isnan,, (_Mdouble_ __value)) __attribute__ ((__const__));
 ^
In file included from /opt/ros/indigo/include/ros/time.h:55:0,
                 from /opt/ros/indigo/include/ros/ros.h:38,
                 from /home/humane/catkin_ws/src/ros_programname/src/programname_node.cc:7:
/usr/include/c++/4.8/cmath:626:3: note: constexpr bool std::isnan(long double)
   isnan(long double __x)
   ^
/usr/include/c++/4.8/cmath:622:3: note: constexpr bool std::isnan(double)
   isnan(double __x)
   ^
/usr/include/c++/4.8/cmath:618:3: note: constexpr bool std::isnan(float)
   isnan(float __x)
   ^
make[2]: *** [CMakeFiles/programname_node.dir/src/programname_node.cc.o] Error 1
make[2]: Leaving directory `/home/humane/catkin_ws/ros_programname_eclipseProject'
make[1]: Leaving directory `/home/humane/catkin_ws/ros_programname_eclipseProject'
make[1]: *** [CMakeFiles/programname_node.dir/all] Error 2
make: *** [all] Error 2
Solution
Probably fixed now. Posted here in the case anyone else has a similar problem:

When I change line 29 of the smile-hearders' general.h it works just fine. Details:
Changed from:

Code: Select all

inline bool DSL_isnan(double x) { using namespace std; return isnan(x) != 0; }
to:

Code: Select all

inline bool DSL_isnan(double x) { return std::isnan(x) != 0; }
Inspired by http://stackoverflow.com/questions/1902 ... nan-to-c11 .
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: Error when compiling with C++ 11 flags [solution found]

Post by shooltz[BayesFusion] »

Thanks for the info. AFAIK, the 'using namespace std' was introduced in DSL_isnan to avoid the very issue you've encountered with -std=c++11 (but of course we were using pre C++ 11 compiler at a time).
Post Reply