SICKAG / sick_scan_xd

Based on the sick_scan drivers for ROS1, sick_scan_xd merges sick_scan, sick_scan2 and sick_scan_base repositories. The driver supports both Linux (native, ROS1, ROS2) and Windows (native and ROS2).
Apache License 2.0
95 stars 85 forks source link

Compile error on native ubuntu 2204 #223

Closed cblesing closed 8 months ago

cblesing commented 10 months ago

Hi,

i have to use the sick_scan_xd library on a native ubuntu c++ project to read out a LSM 1xxx. When I try to compile the library I get a strange error:

`[ 7%] Building CXX object _deps/sick_scan_xd-build/CMakeFiles/sick_scan_xd_lib.dir/driver/src/abstract_parser.cpp.o

: error: token "=" is not valid in preprocessor expressions /home/vagrant/.cpm-source-cache/sick_scan_xd/9da84fc9d165813149d60f87a1b1a46864af7282/include/sick_scan/sick_scan_base.h:62:31: note: in expansion of macro ‘__ROS_VERSION’ 62 | #if !defined __ROS_VERSION || __ROS_VERSION == 0 | ^~~~~~~~~~~~~ : error: token "=" is not valid in preprocessor expressions /home/vagrant/.cpm-source-cache/sick_scan_xd/9da84fc9d165813149d60f87a1b1a46864af7282/include/sick_scan/sick_ros_wrapper.h:118:5: note: in expansion of macro ‘__ROS_VERSION’ 118 | #if __ROS_VERSION <= 1 // ROS-SIMU (native Linux or Windows) or ROS-1 (Linux only) | ^~~~~~~~~~~~~ : error: token "=" is not valid in preprocessor expressions /home/vagrant/.cpm-source-cache/sick_scan_xd/9da84fc9d165813149d60f87a1b1a46864af7282/include/sick_scan/sick_ros_wrapper.h:242:7: note: in expansion of macro ‘__ROS_VERSION’ 242 | #elif __ROS_VERSION == 2 // ROS-2 (Linux or Windows) | ^~~~~~~~~~~~~ In file included from /home/vagrant/.cpm-source-cache/sick_scan_xd/9da84fc9d165813149d60f87a1b1a46864af7282/include/sick_scan/abstract_parser.h:39, from /home/vagrant/.cpm-source-cache/sick_scan_xd/9da84fc9d165813149d60f87a1b1a46864af7282/driver/src/abstract_parser.cpp:63: /home/vagrant/.cpm-source-cache/sick_scan_xd/9da84fc9d165813149d60f87a1b1a46864af7282/include/sick_scan/sick_ros_wrapper.h:446:2: error: #error __ROS_VERSION undefined or unsupported, build with __ROS_VERSION 0, 1 or 2 446 | #error __ROS_VERSION undefined or unsupported, build with __ROS_VERSION 0, 1 or 2 | ^~~~~ : error: token "=" is not valid in preprocessor expressions /home/vagrant/.cpm-source-cache/sick_scan_xd/9da84fc9d165813149d60f87a1b1a46864af7282/include/sick_scan/sick_ros_wrapper.h:453:5: note: in expansion of macro ‘__ROS_VERSION’ 453 | #if __ROS_VERSION == 2 // ROS 2 | ^~~~~~~~~~~~~ : error: token "=" is not valid in preprocessor expressions /home/vagrant/.cpm-source-cache/sick_scan_xd/9da84fc9d165813149d60f87a1b1a46864af7282/include/sick_scan/sick_ros_wrapper.h:491:7: note: in expansion of macro ‘__ROS_VERSION’ 491 | #elif __ROS_VERSION == 1 // ROS 1 | ^~~~~~~~~~~~~ In file included from /home/vagrant/.cpm-source-cache/sick_scan_xd/9da84fc9d165813149d60f87a1b1a46864af7282/include/sick_scan/abstract_parser.h:39, from /home/vagrant/.cpm-source-cache/sick_scan_xd/9da84fc9d165813149d60f87a1b1a46864af7282/driver/src/abstract_parser.cpp:63: /home/vagrant/.cpm-source-cache/sick_scan_xd/9da84fc9d165813149d60f87a1b1a46864af7282/include/sick_scan/sick_ros_wrapper.h:503:10: fatal error: diagnostic_updater/diagnostic_updater.h: No such file or directory 503 | #include | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. gmake[2]: *** [_deps/sick_scan_xd-build/CMakeFiles/sick_scan_xd_lib.dir/build.make:76: _deps/sick_scan_xd-build/CMakeFiles/sick_scan_xd_lib.dir/driver/src/abstract_parser.cpp.o] Error 1 gmake[1]: *** [CMakeFiles/Makefile2:1400: _deps/sick_scan_xd-build/CMakeFiles/sick_scan_xd_lib.dir/all] Error 2 gmake: *** [Makefile:136: all] Error 2` I have added the library by using cmpaddpackage as follows: `CPMAddPackage( NAME sick_scan_xd GIT_REPOSITORY "https://github.com/SICKAG/sick_scan_xd.git" GIT_TAG master )` I have added the library to my project by: `target_link_libraries( sick_scan_xd_lib )` Can anyone help me out?
cblesing commented 10 months ago

I have answered it to my self. I forgot to set the ROS_VERSION ENV to 0. But now I got another error:

[ 13%] Building CXX object _deps/sick_scan_xd-build/CMakeFiles/sick_scan_xd_lib.dir/driver/src/sick_generic_laser.cpp.o In file included from /home/vagrant/.cpm-source-cache/sick_scan_xd/9da84fc9d165813149d60f87a1b1a46864af7282/include/sick_scan/ldmrs/sick_ldmrs_node.h:12, from /home/vagrant/.cpm-source-cache/sick_scan_xd/9da84fc9d165813149d60f87a1b1a46864af7282/driver/src/sick_generic_laser.cpp:70: /home/vagrant/.cpm-source-cache/sick_scan_xd/9da84fc9d165813149d60f87a1b1a46864af7282/include/sick_scan/ldmrs/sick_ldmrs_driver.hpp:58:10: fatal error: sick_ldmrs/manager.hpp: No such file or directory 58 | #include <sick_ldmrs/manager.hpp> | ^~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. gmake[2]: *** [_deps/sick_scan_xd-build/CMakeFiles/sick_scan_xd_lib.dir/build.make:216: _deps/sick_scan_xd-build/CMakeFiles/sick_scan_xd_lib.dir/driver/src/sick_generic_laser.cpp.o] Error 1 gmake[1]: *** [CMakeFiles/Makefile2:1400: _deps/sick_scan_xd-build/CMakeFiles/sick_scan_xd_lib.dir/all] Error 2 gmake: *** [Makefile:136: all] Error 2

How exactly is it possible to disable the LDMRS? I have set this:

option(BUILD_WITH_LDMRS_SUPPORT "Build ${PROJECT_NAME} with LDMRS support (ON, libsick_ldmrs from https://github.com/SICKAG/libsick_ldmrs required) or without LDMRS support (OFF)" OFF) if(WIN32) set(BUILD_WITH_LDMRS_SUPPORT OFF CACHE BOOL "Build ${PROJECT_NAME} with LDMRS support (ON, libsick_ldmrs from https://github.com/SICKAG/libsick_ldmrs required) or without LDMRS support (OFF)" FORCE) elseif(LDMRS EQUAL 0) set(BUILD_WITH_LDMRS_SUPPORT OFF CACHE BOOL "Build ${PROJECT_NAME} with LDMRS support (ON, libsick_ldmrs from https://github.com/SICKAG/libsick_ldmrs required) or without LDMRS support (OFF)" FORCE) else() set(BUILD_WITH_LDMRS_SUPPORT ON CACHE BOOL "Build ${PROJECT_NAME} with LDMRS support (ON, libsick_ldmrs from https://github.com/SICKAG/libsick_ldmrs required) or without LDMRS support (OFF)" FORCE) endif()

rostest commented 10 months ago

Thanks for your feedback. Use cmake flags -DLDMRS=0 -DSCANSEGMENT_XD=0 to build sick_scan_xd without LDMRS and scansegment_xd support, which are not required for LMS 1xxx lidars. See https://github.com/SICKAG/sick_scan_xd/blob/master/INSTALL-GENERIC.md#build-on-linux-generic-without-ros for further options. Please remove all temporary build and cmake files from the build folder to ensure a complete rebuild.

cblesing commented 10 months ago

Thanks for the quick reply. That worked perfectly fine. But is it possible to use the sick_scan_xd without installing it manualy via make install? When I use the CPMAddPackage (we manage any other dependency with it) I ran into the error mentioned here https://github.com/SICKAG/sick_scan_xd/issues/223#issuecomment-1770726130

For some reason in that case the compiler wants to have the sick_ldmrs/manager.hpp even if I have set BUILD_WITH_LDMRS_SUPPORT and BUILD_WITH_SCANSEGMENT_XD_SUPPORT = OFF in the CPMAddPackage options section.

Any idea?

rostest commented 10 months ago

It is possible to use sick_scan_xd without installation. Just make sure that the library can be found, i.e. environment variables PATH and LD_LIBRARY_PATH contain the sick_scan_xd build folder.

sick_generic_laser.cpp includes ldmrs-header, if LDMRS_SUPPORT is defined and not equal 0. It looks like LDMRS_SUPPORT is still defined within the CPM environment; maybe the CPM cache folder (/home/vagrant/.cpm-source-cache) needs to be cleared or removed to ensure a complete rebuild.

swltr commented 9 months ago

(@cblesing and I are working on the same project and are thus facing the same issues, so this can be considered a followup to his comments.)

Using the lib via CPM / a CMake subproject instead of installing it in the system doesn't quite work here, yet. Setting the options to 0 (not any other value like OFF) works and properly seems to turn off LDMRS for the build:

CPMAddPackage(
  NAME sick_scan_xd
  URL ${ARTIFACT_REPO_URL}/sick_scan_xd-3.1.0.tar.gz
  VERSION 3.1.0
  OPTIONS
    "CMAKE_ENABLE_EMULATOR 0"
    "ROS_VERSION 0"
    "LDMRS 0"
    "SCANSEGMENT_XD 0"
)

There is still a problem with includes, though. We link the (static) library to our application like this:

target_link_libraries(exe_myapp
  sick_scan_xd_lib
)

The lib itself is then built successfully as a dependency. But it seems include directories are missing when our own application is compiled:

In file included from /home/vagrant/src/myapp/src/app.myapp/MyApp.cpp:1:
/home/vagrant/src/myapp/src/app.myapp/MyApp.h:15:10: fatal error: sick_scan_xd/sick_scan_api.h: No such file or directory
   15 | #include <sick_scan_xd/sick_scan_api.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

After having a look at sick_scan_xd's CMakeList.txt, I suspect this is because INTERFACE_INCLUDE_DIRECTORIES is not set for the lib via e.g. target_include_directories(${PROJECT_NAME}_lib PUBLIC <DIRECTORIES>) (see CMake manual). I am not a CMake expert, though, and could be wrong there.

If that's the case, it would be great if someone could add the required statements to sick_scan_xd's CMakeList.txt. If it should work nevertheless: How do we properly add required include directories when integrating sick_scan_xd via CPM / as a CMake subproject?

rostest commented 8 months ago

Thanks for following up. We recommend to build a shared library as described in https://github.com/SICKAG/sick_scan_xd/blob/master/doc/sick_scan_api/sick_scan_api.md#build-the-shared-library-on-linux. CPM is currently not supported. Please feel free to append a target_include_directories command in your local CMakeLists.txt file and commit a pull request if the issue can be solved this way.