2

I'm trying to get LSD_SLAM working but when running the catkin_make command at 91%. I get the error message /usr/bin/ld:
/usr/bin/ld: cannot find -lcsparse I already tried to softlink using this command sudo ln -s /usr/local/lib/libg2o_solver_csparse.so /usr/bin/lcsparse.so but this doesn't fix it.

here is the full 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

To be honest I don't know that else I should try as there is nothing called lcsparse in apt either. Furthermore I also tried it on two other computers but still get stuck because of this error.

Here is some information what I have installed, that I thing might be helpful:

  • openCV 4.1.1-pre
  • ROS Melodic
  • Ubuntu 18.04
  • CMake 3.10.2
  • CatKin_tools 0.4.5
  • Python 3.6.8
  • g2o (had to use this old version to fix another bug)

Edit 1:

Here is also the CMakeList.txt

cmake_minimum_required(VERSION 2.8.7)
project(lsd_slam_core)

# Set the build type. Options are:
#  Coverage : w/ debug symbols, w/o optimization, w/ code-coverage
#  Debug : w/ debug symbols, w/o optimization
#  Release : w/o debug symbols, w/ optimization
#  RelWithDebInfo : w/ debug symbols, w/ optimization
#  MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries
set(CMAKE_BUILD_TYPE Release)

find_package(catkin REQUIRED COMPONENTS
  cv_bridge
  OpenCV
  dynamic_reconfigure
  sensor_msgs
  image_transport
  roscpp
  rosbag
  cmake_modules
  lsd_slam_viewer
)

find_package(Eigen3 REQUIRED)
find_package(X11 REQUIRED)
include(cmake/FindG2O.cmake)
include(cmake/FindSuiteParse.cmake)


message("-- CHOLMOD_INCLUDE_DIR : " ${CHOLMOD_INCLUDE_DIR})
message("-- CSPARSE_INCLUDE_DIR : " ${CSPARSE_INCLUDE_DIR})
message("-- G2O_INCLUDE_DIR : " ${G2O_INCLUDE_DIR})

# FabMap
# uncomment this part to enable fabmap
#add_subdirectory(${PROJECT_SOURCE_DIR}/thirdparty/openFabMap)
#include_directories(${PROJECT_SOURCE_DIR}/thirdparty/openFabMap/include)
#add_definitions("-DHAVE_FABMAP")
#set(FABMAP_LIB openFABMAP )

generate_dynamic_reconfigure_options(
  cfg/LSDDebugParams.cfg
  cfg/LSDParams.cfg
)

catkin_package(
  LIBRARIES lsdslam
  DEPENDS EIGEN3 SuiteSparse
  CATKIN_DEPENDS libg2o
)

# SSE flags
add_definitions("-DUSE_ROS")
add_definitions("-DENABLE_SSE")

# Also add some useful compiler flag
set(CMAKE_CXX_FLAGS
   "${CMAKE_CXX_FLAGS} -march=native -Wall -std=c++0x"
)

# Set source files
set(lsd_SOURCE_FILES
  ${PROJECT_SOURCE_DIR}/src/DataStructures/Frame.cpp
  ${PROJECT_SOURCE_DIR}/src/DataStructures/FramePoseStruct.cpp
  ${PROJECT_SOURCE_DIR}/src/DataStructures/FrameMemory.cpp
  ${PROJECT_SOURCE_DIR}/src/SlamSystem.cpp
  ${PROJECT_SOURCE_DIR}/src/LiveSLAMWrapper.cpp
  ${PROJECT_SOURCE_DIR}/src/DepthEstimation/DepthMap.cpp
  ${PROJECT_SOURCE_DIR}/src/DepthEstimation/DepthMapPixelHypothesis.cpp
  ${PROJECT_SOURCE_DIR}/src/util/globalFuncs.cpp
  ${PROJECT_SOURCE_DIR}/src/util/SophusUtil.cpp
  ${PROJECT_SOURCE_DIR}/src/util/settings.cpp
  ${PROJECT_SOURCE_DIR}/src/util/Undistorter.cpp
  ${PROJECT_SOURCE_DIR}/src/Tracking/Sim3Tracker.cpp
  ${PROJECT_SOURCE_DIR}/src/Tracking/Relocalizer.cpp
  ${PROJECT_SOURCE_DIR}/src/Tracking/SE3Tracker.cpp
  ${PROJECT_SOURCE_DIR}/src/Tracking/TrackingReference.cpp
  ${PROJECT_SOURCE_DIR}/src/IOWrapper/Timestamp.cpp
  ${PROJECT_SOURCE_DIR}/src/GlobalMapping/FabMap.cpp
  ${PROJECT_SOURCE_DIR}/src/GlobalMapping/KeyFrameGraph.cpp
  ${PROJECT_SOURCE_DIR}/src/GlobalMapping/g2oTypeSim3Sophus.cpp
  ${PROJECT_SOURCE_DIR}/src/GlobalMapping/TrackableKeyFrameSearch.cpp
)
set(SOURCE_FILES
  ${lsd_SOURCE_FILES}
  ${PROJECT_SOURCE_DIR}/src/IOWrapper/ROS/ROSImageStreamThread.cpp
  ${PROJECT_SOURCE_DIR}/src/IOWrapper/ROS/ROSOutput3DWrapper.cpp
  ${PROJECT_SOURCE_DIR}/src/IOWrapper/OpenCV/ImageDisplay_OpenCV.cpp
)

include_directories(
  include
  ${EIGEN3_INCLUDE_DIR}
  ${PROJECT_SOURCE_DIR}/src
  ${PROJECT_SOURCE_DIR}/thirdparty/Sophus
  ${CSPARSE_INCLUDE_DIR} #Has been set by SuiteParse
  ${CHOLMOD_INCLUDE_DIR} #Has been set by SuiteParse
  ${OpenCV_INCLUDE_DIRS}
  ${catkin_INCLUDE_DIRS}
)

# build shared library.
add_library(lsdslam SHARED ${SOURCE_FILES})
target_link_libraries(lsdslam ${FABMAP_LIB} ${G2O_LIBRARIES} ${catkin_LIBRARIES} csparse cxsparse X11)
#rosbuild_link_boost(lsdslam thread)


# build live ros node
add_executable(live_slam src/main_live_odometry.cpp)
target_link_libraries(live_slam lsdslam ${catkin_LIBRARIES} ${G2O_LIBRARIES})


# build image node
add_executable(dataset src/main_on_images.cpp)
add_dependencies(lsdslam lsd_slam_viewer_generate_messages_cpp)
add_dependencies(live_slam lsd_slam_viewer_generate_messages_cpp)
add_dependencies(dataset lsd_slam_viewer_generate_messages_cpp)
target_link_libraries(dataset lsdslam ${catkin_LIBRARIES} ${G2O_LIBRARIES})
target_link_libraries(live_slam lsdslam ${OpenCV_LIBRARIES})

# TODO add INSTALL

Edit 2:

Fixed the problem with the error message more or less... I added this to the top of my 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
  )

and replaced csparse and cxsparse in the target_linked_libraries with ${CSPARSE_INCLUDE_DIR}. Now I'm stuck with undefined reference at *** see here:

/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
lsd_slam/lsd_slam_core/CMakeFiles/live_slam.dir/build.make:232: recipe for target '/home/alex/Schreibtisch/workspace/devel/lib/lsd_slam_core/live_slam' failed
make[2]: *** [/home/alex/Schreibtisch/workspace/devel/lib/lsd_slam_core/live_slam] Error 1
CMakeFiles/Makefile2:2348: recipe for target 'lsd_slam/lsd_slam_core/CMakeFiles/live_slam.dir/all' failed
make[1]: *** [lsd_slam/lsd_slam_core/CMakeFiles/live_slam.dir/all] Error 2
Makefile:140: recipe for target 'all' failed

HERE is also the full output.

MrMinemeet
  • 304
  • 6
  • 17
  • the `csparse` library should have come with the `libsuitesparse-dev` apt package you should have installed. Can you show more of the build output? For example, what does the CMake print for the CSPARSE include path here: `-- CSPARSE_INCLUDE_DIR : ......` ? This might help narrow down the issue. I am assuming `/usr/bin/lcsparse.so` exists? – Kevin Jul 17 '19 at 14:15
  • @squareskittles `libsuitesparse-dev` version 1:5.1.2-2 (newest) is installed. Thb. I don't know where to find the outputlog. In the CMakeCache.txt I found this line: `CSPARSE_INCLUDE_DIR:PATH=/usr/include/suitesparse` if that's what you ment with the CMake print. `/usr/bin/lcsparse exits because I used a link (explained above) but I guess thats' wrong suposing I should use suietsparse and not the one from g2o. [HERE](https://pastebin.com/bGxP1aaP) is also the full CMakeCache.txt – MrMinemeet Jul 17 '19 at 17:58
  • I don't know much about `libsuitesparse-dev` but I would assume it would install the `csparse` library on your system. Also, the `-l` is an indicator to the compiler to *link* that library, so the library name should be `csparse.so` or `libcsparse.so` in order for the linker to find it. – Kevin Jul 17 '19 at 18:05
  • According to [Ubuntu Packages](https://packages.ubuntu.com/bionic/amd64/libsuitesparse-dev/filelist) the `libsuitesparse-dev` creates a `libcxsparse.so` file in `/usr/lib/x86_64-linux-gnu/` so I tried to link this file to the `/usr/bin/` location with different names (these: `lcsparse.so libcsparse lcsparse libcsparse.so csparse csparse.so`) just to check if anyone would work but still nothing – MrMinemeet Jul 17 '19 at 19:05
  • The CMake for this project has the line: `target_link_libraries(lsdslam ${FABMAP_LIB} ${G2O_LIBRARIES} ${catkin_LIBRARIES} csparse cxsparse X11)`. So, it will try to link against the `csparse` and `cxsparse` libraries. Instead of using symlinks, you might consider adding the location these libraries were installed to your `Path` environment variable. – Kevin Jul 17 '19 at 20:04
  • I added them to `PATH` like this `/opt/ros/melodic/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/x86_64-linux-gnu` but I'm still getting the same error. Might it be possible because `libsuitesparse-dev` only creates a `libcxsparse.so` and not a `libcsparse.so` file? Do you know how to get both? – MrMinemeet Jul 18 '19 at 07:56

3 Answers3

1

Ok I fixed it myself. Here are the steps I did. First I made the steps explained in EDIT 2. After that i got some undefined reference stuff which I fixed by first installing libsuitesparse-dev and then compiling g2o
It worked for me so I hope it works for you too.

MrMinemeet
  • 304
  • 6
  • 17
1

I would have commented, but I could not due to too low rep.

For me it was enough to add ${CSPARSE_INCLUDE_DIR} to target_link_libraries. So the line in my CMakeLists.txt looks like this:

target_link_libraries(lsdslam ${FABMAP_LIB} ${G2O_LIBRARIES} ${catkin_LIBRARIES} ${CSPARSE_INCLUDE_DIR} cxsparse X11)
Knalltuete
  • 41
  • 1
  • 7
0

(not enough points to comment)

I was just struggling with this too over the last couple of nights. I found that the 18.04/bionic version of the 'libsuitesparse-dev' package for some reason has left the plain csparse file out. It only has the 'libcxsparse3' one now. https://packages.ubuntu.com/bionic/libsuitesparse-dev

If you go back an ubuntu version you'll see that it used to have the 'plain' csparse file. https://packages.ubuntu.com/xenial/libsuitesparse-dev

UPDATE: I filed an Ubuntu bug report but got the reply that libcsparse has been superseded by libcxsparse.

"Thank you for your bug report, it's a wanted change and not a bug according to https://salsa.debian.org/science-team/suitesparse/-/commit/3b00ddd5 '+ Drop package for CSparse (libcsparse), superseded by libcxsparse.' , did you try to use this one?"

** Changed in: suitesparse (Ubuntu) Status: New => Invalid