Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ch3 and Ch4 PlotTrajectory Compiling Error and Solution [bug fix] #76

Closed
hanzheteng opened this issue Mar 3, 2020 · 3 comments
Closed

Comments

@hanzheteng
Copy link
Contributor

hanzheteng commented Mar 3, 2020

According to https://www.cnblogs.com/MT-ComputerVision/p/6349872.html
The CMakeLists.txt file in Chapter 3 and Chapter 4 can add C++ 11 support as the following:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

Previously, the compiling error is the following:

Scanning dependencies of target plotTrajectory
[ 25%] Building CXX object CMakeFiles/plotTrajectory.dir/plotTrajectory.o
In file included from /usr/include/c++/5/type_traits:35:0,
                 from /usr/local/include/pangolin/compat/type_traits.h:34,
                 from /usr/local/include/pangolin/utils/type_convert.h:34,
                 from /usr/local/include/pangolin/utils/params.h:31,
                 from /usr/local/include/pangolin/display/display.h:33,
                 from /usr/local/include/pangolin/gl/gl.hpp:32,
                 from /usr/local/include/pangolin/gl/gl.h:248,
                 from /usr/local/include/pangolin/pangolin.h:33,
                 from /home/hteng/slambook2/ch3/examples/plotTrajectory.cpp:1:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support \
  ^
In file included from /usr/local/include/pangolin/utils/assert.h:31:0,
                 from /usr/local/include/pangolin/platform.h:80,
                 from /usr/local/include/pangolin/pangolin.h:30,
                 from /home/hteng/slambook2/ch3/examples/plotTrajectory.cpp:1:
/usr/local/include/pangolin/utils/format_string.h:40:30: error: expected type-specifier before ‘decltype’
     static auto test(int) -> decltype( (std::declval<std::stringstream&>() << std::declval<TT>(), std::true_type()) );
                              ^
/usr/local/include/pangolin/utils/format_string.h:40:30: error: expected initializer before ‘decltype’
/usr/local/include/pangolin/utils/format_string.h:43:35: error: ‘false_type’ in namespace ‘std’ does not name a type
     static auto test(...) -> std::false_type;
                                   ^
/usr/local/include/pangolin/utils/format_string.h:43:35: error: conflicting specifiers in declaration of ‘test’
/usr/local/include/pangolin/utils/format_string.h:46:40: error: ‘test’ was not declared in this scope
     static const bool value = decltype(test<T>(0))::value;
                                        ^

and

In file included from /usr/local/include/pangolin/var/var.h:34:0,
                 from /usr/local/include/pangolin/var/varextra.h:31,
                 from /usr/local/include/pangolin/pangolin.h:49,
                 from /home/hteng/slambook2/ch3/examples/plotTrajectory.cpp:1:
/usr/local/include/pangolin/var/varvalue.h: In instantiation of ‘void pangolin::VarValue<T>::Init() [with T = bool]’:
/usr/local/include/pangolin/var/varvalue.h:55:13:   required from ‘pangolin::VarValue<T>::VarValue(const T&) [with T = bool]’
/usr/local/include/pangolin/var/var.h:177:20:   required from ‘pangolin::Var<T>::Var(const string&, const T&, bool) [with T = bool; std::__cxx11::string = std::__cxx11::basic_string<char>]’
/usr/local/include/pangolin/var/varextra.h:67:52:   required from here
/usr/local/include/pangolin/var/varvalue.h:99:23: error: ‘class pangolin::VarValue<bool>’ has no member named ‘str’
             this->str = (VarValueT<std::string>*)this;
                       ^
/usr/local/include/pangolin/var/varvalue.h:102:23: error: ‘class pangolin::VarValue<bool>’ has no member named ‘str’
             this->str = str_ptr;
                       ^
CMakeFiles/plotTrajectory.dir/build.make:62: recipe for target 'CMakeFiles/plotTrajectory.dir/plotTrajectory.o' failed
make[2]: *** [CMakeFiles/plotTrajectory.dir/plotTrajectory.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/plotTrajectory.dir/all' failed
make[1]: *** [CMakeFiles/plotTrajectory.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

@hanzheteng
Copy link
Contributor Author

hanzheteng commented Mar 3, 2020

Duplicated issue #24 .
However, the problem mentioned in issue #39 still exists.
cannot find trajectory file at ./examples/trajectory.txt

Update: The problem mentioned in issue #39 can be solved by changing the file path from
string trajectory_file = "./examples/trajectory.txt";
to string trajectory_file = "./trajectory.txt"; if you want to run in within examples folder.

@hanzheteng
Copy link
Contributor Author

hanzheteng commented Mar 4, 2020

I suspect that this bug only happens on Ubuntu 16 system which has a lower version of gcc compiler.

The default gcc version used in Ubuntu 16 and Ubuntu 18 OS are 5.4.0 and 7.4.0, respectively. According to the release note of gcc 6.0 version, The default mode for C++ is now -std=gnu++14 instead of -std=gnu++98. (Therefore, it passed the test when the author compiled it on the Ubuntu 18 OS.)

By the way, it is also better to add the following code at the beginning of the CMakeLists.txt file in the ch3/example folder.

cmake_minimum_required(VERSION 2.8)
project(examples)

@hanzheteng hanzheteng changed the title Ch3 PlotTrajectory Compiling Error and Solution [bug fix] Ch3 and Ch4 PlotTrajectory Compiling Error and Solution [bug fix] Mar 5, 2020
@hanzheteng
Copy link
Contributor Author

To summarize, in Chapter 3 and Chapter 4, if running on Ubuntu 16 OS, the C++ 11 support is also required. Adding the following line to the CMakeLists can solve the problem.

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

In addition, in Chapter 3, the path to the trajectory file needs to be changed, as mentioned above.

In Chapter 4, there are two solutions for the linking problem on sophus header files.

  1. Do not install Sophus and use local path instead. For example, in the source file useSophus.cpp, the include path can be changed to
#include "../3rdparty/Sophus/sophus/se3.hpp"
  1. Install the Sophus library to the system.
cd 3rdparty/Sophus/build
cmake ..
make
sudo make install

and you will see that the header files are copies to one of the search path in Linux system /usr/local/include/, as listed in the PATH environment variable.

user@hostname:~/slambook2/3rdparty/Sophus/build$ sudo make install
[  9%] Built target test_geometry
[ 18%] Built target test_rxso2
[ 27%] Built target test_se3
[ 36%] Built target test_velocities
[ 45%] Built target test_so2
[ 54%] Built target test_sim2
[ 63%] Built target test_so3
[ 72%] Built target test_sim3
[ 81%] Built target test_common
[ 90%] Built target test_se2
[100%] Built target test_rxso3
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/share/sophus/cmake/SophusTargets.cmake
-- Installing: /usr/local/share/sophus/cmake/SophusConfig.cmake
-- Installing: /usr/local/share/sophus/cmake/SophusConfigVersion.cmake
-- Installing: /usr/local/include/sophus/average.hpp
-- Installing: /usr/local/include/sophus/common.hpp
-- Installing: /usr/local/include/sophus/geometry.hpp
-- Installing: /usr/local/include/sophus/interpolate.hpp
-- Installing: /usr/local/include/sophus/interpolate_details.hpp
-- Installing: /usr/local/include/sophus/num_diff.hpp
-- Installing: /usr/local/include/sophus/rotation_matrix.hpp
-- Installing: /usr/local/include/sophus/rxso2.hpp
-- Installing: /usr/local/include/sophus/rxso3.hpp
-- Installing: /usr/local/include/sophus/se2.hpp
-- Installing: /usr/local/include/sophus/se3.hpp
-- Installing: /usr/local/include/sophus/sim2.hpp
-- Installing: /usr/local/include/sophus/sim3.hpp
-- Installing: /usr/local/include/sophus/sim_details.hpp
-- Installing: /usr/local/include/sophus/so2.hpp
-- Installing: /usr/local/include/sophus/so3.hpp
-- Installing: /usr/local/include/sophus/types.hpp
-- Installing: /usr/local/include/sophus/velocities.hpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant