# LSD-SLAM Knowledge Base
## Information
Knowledge base for errors and how to fix them. Based on errors I encountered while compiling [my fork](https://github.com/MrMinemeet/lsd_slam), the [fork by kevin george](https://github.com/kevin-george/lsd_slam) and the [fork by TUM-Vision](https://github.com/tum-vision/lsd_slam)
---
## Errors
### Cannot bind non_const lvalue to rvalue
#### Error Message
```
PointCloudViewer.h:136:26: error: cannot bind non-const lvalue reference of type ‘qreal& {aka double&}’ to an rvalue of type ‘qreal {aka double}’
frame.getPosition(x,y,z);
PointCloudViewer.cpp:327:44: error: cannot bind non-const lvalue reference of type ‘qreal& {aka double&}’ to an rvalue of type ‘qreal {aka double}’
camera()->frame()->getPosition(x,y,z);
```
#### Solution
Change the `float x,y,z;` in the files to `double x,y,z;`
### no such function found: `g2o::OptimizationAlgorithmLevenberg`
#### Solution
uninstall `ros-melodic-libg2o` using `sudo apt purge ros-melodic-libg2o` and then run `sudo rm -r /usr/local/lib/libg2o* /usr/local/include/g2o /usr/local/lib/g2o /usr/local/bin/g2o*` to remove all the g2o stuff that is left
Then install the `g2o c++03` again
### Couldn't find package configuration file provided by 'Eigen'
#### Error Message
```
lsd_slam/lsd_slam_viewer/CMakeLists.txt:30 (find_package):
By not providing "FindEigen.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Eigen", but
CMake did not find one.
Could not find a package configuration file provided by "Eigen" with any of
the following names:
EigenConfig.cmake
eigen-config.cmake
Add the installation prefix of "Eigen" to CMAKE_PREFIX_PATH or set
"Eigen_DIR" to a directory containing one of the above files. If "Eigen"
provides a separate development package or SDK, be sure it has been
installed.
```
#### Solution
In the CMakeList.txt change `Eigen` with `Eigen3`
### `'int' enum Status`
#### Error Message
```
In file included from /usr/include/GL/glx.h:30:0,
from /home/adas/lsd-SLAM_wx/src/lsd_slam/lsd_slam_viewer/src/KeyFrameDisplay.cpp:27:
/usr/include/opencv2/stitching.hpp:128:10: error: expected identifier before ‘int’
enum Status
^
In file included from /usr/include/opencv2/opencv.hpp:86:0,
from /home/adas/lsd-SLAM_wx/src/lsd_slam/lsd_slam_viewer/src/KeyFrameDisplay.cpp:31:
/usr/include/opencv2/stitching.hpp:129:5: error: expected unqualified-id before ‘{’ token
{
```
#### Solution
Rename `Status` to `status`
https://github.com/opencv/opencv/pull/7148/commits/7810bcd4bd4e6cae06e191fbb8a0c7e369b03120
### "lsd_slam_viewer/keyframeMsg.h" not found
#### Error Message
```
lsd_slam/lsd_slam_viewer/src/KeyFrameDisplay.h:27:10: fatal error: lsd_slam_viewer/keyframeMsg.h: No such file or directory
#include "lsd_slam_viewer/keyframeMsg.h"
...
lsd_slam/lsd_slam_viewer/src/PointCloudViewer.h:30:10: fatal error: lsd_slam_viewer/keyframeMsg.h: No such file or directory
#include "lsd_slam_viewer/keyframeMsg.h"
```
#### Solution
Do all these step
* Copy `msg` directory under `lsd_slam_viewer` into `lsd_slam_core`
* Replace all instances of `lsd_slam_viewer` in the `IOWrapper/ROS/ROSOutput3DWrapper.cpp` file with `lsd_slam_core`
###### Viewer
* Add `add_dependencies(viewer lsd_slam_viewer_generate_messages_cpp)` in `lsd_slam_viewer/CMakelists.txt` under the `add_executeable` line
###### Core
* Add `message_generation` to the list of `find_package(catkin REQUIRED COMPONENTS)`
* Add `add_message_files(DIRECTORY msg FILES keyframeMsg.msg keyframeGraphMsg.msg)
generate_messages(DEPENDENCIES)` above the line stating `generate_dynamic_reconfigure_options`
* Add `add_dependencies(live_slam lsd_slam_core_generate_messages_cpp)` under the `add_executeable` line
> [Credit](https://github.com/tum-vision/lsd_slam/issues/92#issuecomment-427723074)
### base_vertex.h not found
#### Error Message
```
lsd_slam/lsd_slam_core/src/GlobalMapping/g2oTypeSim3Sophus.h:24:10: fatal error: g2o/core/base_vertex.h: No such file or directory
#include "g2o/core/base_vertex.h"
```
#### Solution
Clone and compile g2o yourself
* Clone https://github.com/RainerKuemmerle/g2o
* Install dependencys
- cmake
- libeigen3-dev
* Compile
- `mkdir build`
- `cd build`
- `cmake ..`
- `make`
### g2oTypeSim3Sophus.h Errors
#### Error Message
Many error messages like the one below in the g2oTypeSim3Sophus.h file
```
lsd_slam/lsd_slam_core/src/GlobalMapping/g2oTypeSim3Sophus.h:96:20: error: ISO C++ forbids declaration of ‘type name’ with no type [-fpermissive]
Eigen::Map<const g2o::Vector7d> v(m);
...
lsd_slam/lsd_slam_core/src/GlobalMapping/g2oTypeSim3Sophus.h:96:33: error: template argument 1 is invalid
Eigen::Map<const g2o::Vector7d> v(m);
```
#### Solution
Change line 96 in g2oTypeSim3Sophus.h from `Eigen::Map<const g2o::Vector7d> v(m);` to `Eigen::Map<const Eigen::Matrix<double, 7 ,1> > v(m);`
> [Credit](https://github.com/tum-vision/lsd_slam/issues/313#issuecomment-442411285)
### g2o No matching function for call
#### Error Message
```
no matching function for call to ‘g2o::BlockSolver<g2o::BlockSolverTraits<7, 3>>::BlockSolver(LinearSolver*&)’
BlockSolver* blockSolver = new BlockSolver(solver);
```
#### Solution
Install version **c++03** from the link below as the latest one changed a few things. Still works with the fix for `base_vertex.h not found` as written above.
https://github.com/felixendres/g2o/tree/c++03
### ros/ros.h not found
#### Error Message
```
lsd_slam/lsd_slam_core/src/IOWrapper/ROS/ROSImageStreamThread.h:27:10: fatal error: ros/ros.h: No such file or directory
```
#### Solution
Add `${catkin_INCLUDE_DIRS}` to the `include_directories` in the CMakeList.txt.
> [Credit](https://answers.ros.org/question/283665/fatal-error-rosrosh-no-such-file-or-directory/?answer=283669#post-id-283669)
### cannot find -lcparse
#### Error Message
`/usr/bin/ld: cannot find -lcsparse`
#### Solution
* Find the `csparse` file with `sudo find / -name "*csparse*"`
In my case it was in `/usr/local/lib/libg2o_solver_csparse.so`
* Now softlink `csparse` we just found to the location it is missing in with command `sudo ln -s {where it is} {where to link it}`
### 'cvPoint' and 'CV_FONT_HERSHEY_SIMPLEX' not declared in this scope
#### Error Message
```
src/lsd_slam/lsd_slam_core/src/util/globalFuncs.cpp: In function ‘void lsd_slam::printMessageOnCVImage(cv::Mat&, std::__cxx11::string, std::__cxx11::string)’:
src/lsd_slam/lsd_slam_core/src/util/globalFuncs.cpp:52:28: error: ‘cvPoint’ was not declared in this scope
cv::putText(image, line2, cvPoint(10,image.rows-5),
^~~~~~~
src/lsd_slam/lsd_slam_core/src/util/globalFuncs.cpp:52:28: note: suggested alternative: ‘cvRound’
cv::putText(image, line2, cvPoint(10,image.rows-5),
^~~~~~~
cvRound
```
and
```
src/lsd_slam/lsd_slam_core/src/util/globalFuncs.cpp:53:6: error: ‘CV_FONT_HERSHEY_SIMPLEX’ was not declared in this scope
CV_FONT_HERSHEY_SIMPLEX, 0.4, cv::Scalar(200,200,250), 1, 8);
```
#### Solution
Don't mix the obsolete C api with the C++ api. Use `cv::Point` instead of `cvPoint`, and `cv::FONT_HERSHEY_SIMPLEX` instead of `CV_FONT_HERSHEY_SIMPLEX`
> [Credit](https://stackoverflow.com/a/57053579/8527195)
>
### 'cvPoint', 'CV_FONT_HERSHEY_SIMPLEX', ... not declared in this scope
#### Error Message
```
/home/adas/ros_workspace/src/src/lsd_slam/lsd_slam_core/src/util/globalFuncs.cpp: In function ‘void lsd_slam::printMessageOnCVImage(cv::Mat&, std::__cxx11::string, std::__cxx11::string)’:
/home/adas/ros_workspace/src/src/lsd_slam/lsd_slam_core/src/util/globalFuncs.cpp:52:28: error: ‘cvPoint’ was not declared in this scope
cv::putText(image, line2, cvPoint(10,image.rows-5),
^~~~~~~
/home/adas/ros_workspace/src/src/lsd_slam/lsd_slam_core/src/util/globalFuncs.cpp:52:28: note: suggested alternative: ‘cvRound’
cv::putText(image, line2, cvPoint(10,image.rows-5),
^~~~~~~
cvRound
```
and
```/home/adas/ros_workspace/src/src/lsd_slam/lsd_slam_core/src/util/globalFuncs.cpp:53:6: error: ‘CV_FONT_HERSHEY_SIMPLEX’ was not declared in this scope
CV_FONT_HERSHEY_SIMPLEX, 0.4, cv::Scalar(200,200,250), 1, 8);
```
most other that have something with `cv` or `CV_` at the front
#### Solution
Don't mix the obsolete C api with the C++ api. Use `cv::Point` instead of `cvPoint`, and `cv::FONT_HERSHEY_SIMPLEX` instead of `CV_FONT_HERSHEY_SIMPLEX`, e.g.:
```
cv::putText(image, line1, cv::Point(10,image.rows-18),
cv::FONT_HERSHEY_SIMPLEX, 0.4, cv::Scalar(200,200,250), 1, 8);
```
>[Credits](https://stackoverflow.com/a/57053579/8527195)
### catkin_make » /usr/bin/ld: cannot find -lcsparse
This occured when running `catkin_make` to make `lsd_slam`
#### Error Message
```
[ 91%] Linking CXX shared library /home/adas/lsd-slam_workspace/devel/lib/liblsdslam.so
/usr/bin/ld: cannot find -lcsparse
collect2: error: ld returned 1 exit status
lsd_slam/lsd_slam_core/CMakeFiles/lsdslam.dir/build.make:755: recipe for target '/home/adas/lsd-slam_workspace/devel/lib/liblsdslam.so' failed
make[2]: * [/home/adas/lsd-slam_workspace/devel/lib/liblsdslam.so] Error 1 CMakeFiles/Makefile2:2385: recipe for target 'lsd_slam/lsd_slam_core/CMakeFiles/lsdslam.dir/all' failed
make[1]: [lsd_slam/lsd_slam_core/CMakeFiles/lsdslam.dir/all] Error 2 Makefile:140: recipe for target 'all' failed
make: ** [all] Error 2
Invoking "make -j4 -l4" failed
```
#### Solution
Add this at the top of the `CMakeList.txt`
```
find_path(CSPARSE_INCLUDE_DIR NAMES cs.h
PATHS
/usr/include/suitesparse
/usr/include
/opt/local/include
/usr/local/include
/sw/include
/usr/include/ufsparse
/opt/local/include/ufsparse
/usr/local/include/ufsparse
/sw/include/ufsparse
PATH_SUFFIXES
suitesparse
)
```
Also replace `csparse` and `cxsparse` in the `target_linked_libraries` with `${CSPARSE_INCLUDE_DIR}`
> [Credit](https://stackoverflow.com/a/57092644/8527195)
### `liblsdslam.so: Warning: undefined reference to ***`
Will most Likely accure when applying the fix for "catkin_make » /usr/bin/ld: cannot find -lcsparse"
#### Error Message
`"Warnung: undefinerter Verweis auf xxx"` => `"Warning: undefined reference to xxx`
```
/home/alex/Schreibtisch/workspace/devel/lib/liblsdslam.so: Warnung: undefinierter Verweis auf »cs_di_post«
/home/alex/Schreibtisch/workspace/devel/lib/liblsdslam.so: Warnung: undefinierter Verweis auf »cs_di_etree«
/home/alex/Schreibtisch/workspace/devel/lib/liblsdslam.so: Warnung: undefinierter Verweis auf »g2o::csparse_extension::cs_chol_workspace(cs_di_sparse const*, cs_di_symbolic const*, int*, double*)«
/home/alex/Schreibtisch/workspace/devel/lib/liblsdslam.so: Warnung: undefinierter Verweis auf »cs_di_pinv«
/home/alex/Schreibtisch/workspace/devel/lib/liblsdslam.so: Warnung: undefinierter Verweis auf »cs_di_counts«
/home/alex/Schreibtisch/workspace/devel/lib/liblsdslam.so: Warnung: undefinierter Verweis auf »cs_di_sfree«
/home/alex/Schreibtisch/workspace/devel/lib/liblsdslam.so: Warnung: undefinierter Verweis auf »cs_di_spfree«
/home/alex/Schreibtisch/workspace/devel/lib/liblsdslam.so: Warnung: undefinierter Verweis auf »g2o::csparse_extension::cs_cholsolsymb(cs_di_sparse const*, double*, cs_di_symbolic const*, double*, int*)«
/home/alex/Schreibtisch/workspace/devel/lib/liblsdslam.so: Warnung: undefinierter Verweis auf »cs_di_nfree«
/home/alex/Schreibtisch/workspace/devel/lib/liblsdslam.so: Warnung: undefinierter Verweis auf »cs_di_amd«
/home/alex/Schreibtisch/workspace/devel/lib/liblsdslam.so: Warnung: undefinierter Verweis auf »cs_di_cumsum«
/home/alex/Schreibtisch/workspace/devel/lib/liblsdslam.so: Warnung: undefinierter Verweis auf »cs_di_symperm«
/home/alex/Schreibtisch/workspace/devel/lib/liblsdslam.so: Warnung: undefinierter Verweis auf »cs_di_schol«
/home/alex/Schreibtisch/workspace/devel/lib/liblsdslam.so: Warnung: undefinierter Verweis auf »cs_di_calloc«
/home/alex/Schreibtisch/workspace/devel/lib/liblsdslam.so: Warnung: undefinierter Verweis auf »cs_di_malloc«
/home/alex/Schreibtisch/workspace/devel/lib/liblsdslam.so: Warnung: undefinierter Verweis auf »cs_di_free«
/home/alex/Schreibtisch/workspace/devel/lib/liblsdslam.so: Warnung: undefinierter Verweis auf »g2o::csparse_extension::writeCs2Octave(char const*, cs_di_sparse const*, bool)«
collect2: error: ld returned 1 exit status
```
### Solution
Install `libsuitesparse-dev` before compiling `g2o`
### double free or corruption
#### Error Message
```
double free or corruption (out)
Aborted (core dumped)
```
#### Solution
[Download](https://bitbucket.org/eigen/eigen/downloads/?tab=tags) `Eigen 3.2.5` but don't install it.
Put it in a folder and remember the path.
Go into the `CMakeList.txt` of `lsd_slam_core` and add `set(EIGEN3_INCLUDE_DIR "{PATH}")` above the block `include_directories(...`
### 'CV_GRAY2RGB' & 'CV_RGB2GRAY' not declared
#### Error Message
```
error: ‘CV_GRAY2RGB’ was not declared in this scope
cv::cvtColor(keyFrameImage8u, res, CV_GRAY2RGB);
```
#### Solution
Change `CV_` to `cv::COLOR_` like this: `cv::COLOR_GRAY2RGB`