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

Unable to build with c++17 #959

Closed
Neumann-A opened this issue Jan 23, 2023 · 12 comments
Closed

Unable to build with c++17 #959

Neumann-A opened this issue Jan 23, 2023 · 12 comments

Comments

@Neumann-A
Copy link

Neumann-A commented Jan 23, 2023

rtabmap seems to use a bunch of deprecated functions blocking the build using Qt6

D:\buildtrees\rtabmap\src\v0.20.16-df5c73836d.clean\corelib\src\rtflann/util/heap.h(118): error C2039: 'binary_function': is not a member of 'std'

D:\buildtrees\rtabmap\src\v0.20.16-df5c73836d.clean\corelib\src\rtflann/util/random.h(120): error C2039: 'random_shuffle': is not a member of 'std'

D:\buildtrees\rtabmap\src\v0.20.16-df5c73836d.clean\corelib\src\rtflann/algorithms/dist.h(522): error C2065: 'pop_t': undeclared identifier

see : https://github.com/microsoft/vcpkg/pull/29078/files#diff-fef086b12acd48845cf68584a877b222d095bee60876c0b98c6a04768e8a8b9f

@matlabbe
Copy link
Member

matlabbe commented Jan 23, 2023

Try master branch, c++17 should work

thanks for the link, I’ll keep in mind when I will try qt6

@Neumann-A
Copy link
Author

Try master branch, c++17 should work

No it won't. Your vendored flann is outdated and still uses std::binary_function and random_schuffle.

struct CompareT : public std::binary_function<T,T,bool>

std::random_shuffle(vals_.begin(), vals_.end(), generator);

just to point out two occurrences in the code.

@matlabbe
Copy link
Member

You are right, for some reason I thought I already built it on c++17, but it was c++14

rtabmap/CMakeLists.txt

Lines 746 to 755 in ff61266

#LOAM, PCL>=1.10, latest g2o and CCCoreLib require c++14, but MSCKF_VIO requires c++11
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
IF(COMPILER_SUPPORTS_CXX14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
set(CMAKE_CXX_STANDARD 14)
ELSE()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support. Please use a different C++ compiler if you want to use LOAM, latest PCL or g2o.")
ENDIF()
ENDIF()

I'll check to update flann, hopefully it won't break older machine configurations.

@matlabbe
Copy link
Member

matlabbe commented Feb 5, 2023

Well, on ubuntu 20.04, setting explicitly to c++17 doesn't cause any building issues:

--   CMAKE_CXX_FLAGS =  -fmessage-length=0  -fopenmp -std=c++17
--   FLANN_KDTREE_MEM_OPT = OFF
--   PCL_DEFINITIONS = -DDISABLE_OPENNI2;-DDISABLE_PCAP;-DDISABLE_PNG;-DDISABLE_LIBUSB_1_0
--   PCL_VERSION = 1.10.0
-- 
-- Optional dependencies ('*' affects some default parameters) :
--  *With OpenCV 4.2.0 xfeatures2d = NO, nonfree = NO (License: BSD)
--   With Qt 5.12.8            = YES (License: Open Source or Commercial)
--   With VTK 7.1              = YES (License: BSD)

I'll try with in a docker 22.04 + Qt6...

@Neumann-A
Copy link
Author

If it compiles with the stuff mentioned in #959 (comment) and c++17 then your c++ library is non conforming. But you probably want to check the build logs instead of the configure log if c++17 is really applied and cmake didn't add c++14 add the end.

@matlabbe
Copy link
Member

matlabbe commented Feb 6, 2023

I've been updating to Qt6 on this pull request #968 with latest VTK/PCL and OpenCV, using c++17, and I still don't see the errors (this is a docker on Ubuntu 22.04)...

[  5%] Building CXX object corelib/src/CMakeFiles/rtabmap_core.dir/VWDictionary.cpp.o
cd /root/rtabmap/build/corelib/src && /usr/bin/c++ -DBOOST_ALL_NO_LIB -DBOOST_ATOMIC_DYN_LINK -DBOOST_CHRONO_DYN_LINK -DBOOST_DATE_TIME_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_IOSTREAMS_DYN_LINK -DBOOST_PROGRAM_OPTIONS_DYN_LINK -DBOOST_SERIALIZATION_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_THREAD_DYN_LINK -DDISABLE_OPENNI2 -DDISABLE_PCAP -DDISABLE_PNG -DG2O_USE_VENDORED_CERES -DPCL_OMP -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_NO_KEYWORDS -DQT_OPENGLWIDGETS_LIB -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -Dkiss_fft_scalar=double -Drtabmap_core_EXPORTS -I/root/rtabmap/build/corelib/src/../include -I/root/rtabmap/utilite/include -I/root/rtabmap/corelib/src/../include -I/root/rtabmap/corelib/src -I/root/rtabmap/build/corelib/src -I/usr/include/openni2 -I/usr/include/dc1394 -I/usr/include/hidapi -isystem /usr/local/include/opencv4 -isystem /usr/local/include/pcl-1.13 -isystem /usr/include/eigen3 -isystem /usr/include/ni -isystem /opt/ros/humble/include -isystem /usr/local/include/vtk-9.2 -isystem /usr/local/include/vtk-9.2/vtknlohmannjson/include -isystem /usr/local/include/vtk-9.2/vtkfreetype/include -isystem /usr/include/x86_64-linux-gnu/qt6/QtOpenGL -isystem /usr/include/x86_64-linux-gnu/qt6 -isystem /usr/include/x86_64-linux-gnu/qt6/QtCore -isystem /usr/lib/x86_64-linux-gnu/qt6/mkspecs/linux-g++ -isystem /usr/include/x86_64-linux-gnu/qt6/QtGui -isystem /usr/include/x86_64-linux-gnu/qt6/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt6/QtOpenGLWidgets -isystem /opt/ros/humble/include/g2o/solvers/pcg -isystem /opt/ros/humble/include/g2o/solvers/csparse -isystem /usr/include/suitesparse -isystem /opt/ros/humble/include/g2o/solvers/cholmod -fmessage-length=0 -fopenmp -std=c++17 -O3 -DNDEBUG -fPIC   -Wall -Wno-unknown-pragmas -msse4.2 -mfpmath=sse -march=native -mavx2 -fPIC -fopenmp -MD -MT corelib/src/CMakeFiles/rtabmap_core.dir/VWDictionary.cpp.o -MF CMakeFiles/rtabmap_core.dir/VWDictionary.cpp.o.d -o CMakeFiles/rtabmap_core.dir/VWDictionary.cpp.o -c /root/rtabmap/corelib/src/VWDictionary.cpp
[  5%] Linking CXX shared library ../../bin/librtabmap_core.so
cd /root/rtabmap/build/corelib/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/rtabmap_core.dir/link.txt --verbose=1
/usr/bin/c++ -fPIC  -fmessage-length=0 -fopenmp -std=c++17 -O3 -DNDEBUG -shared -Wl,-soname,librtabmap_core.so.0.20 -o ../../bin/librtabmap_core.so.0.20.23

Maybe it is related to compiler on windows? I'll continue to keep on eye on this, and fix it when I will get the error.

@matlabbe
Copy link
Member

@Neumann-A I integrated your changes on latest master. The new 0.21.0 version is also now using cmake targets. I tried vcpkg build and cleanup the patches to build everything. See my pull request here: microsoft/vcpkg#30254. If you can comment on it it would appreciated.

With VCPKG, the only issue I have right know is that Qt6 plugins are not copied in tools/rtabmap, so if you launch any rtabmap's app/tool using qt, you will have a qt error that windows plugin is not found. A workaround is to set QT_PLUGIN_PATH as an environment variable (for me it is set to C:\vcpkg\installed\x64-windows-release\Qt6\plugins)

I tried microsoft/vcpkg#20101 (comment) in rtabmap's port file but I got cmake error during the build. I don't know where to put this.

@Neumann-A
Copy link
Author

Have you tried to use https://www.qt.io/blog/cmake-deployment-api for deployment?

Another solution might be to just copy the qt.conf from tools/Qt6/bin

@matlabbe
Copy link
Member

Thank you for the reviewing the PR, I am currently making the changes. For qt deployment, I missed that webpage, I tried the first time this, but saw after testing it was only for Qt 6.5, while vcpkg uses Qt 6.4. Then I tried this, which ultimately worked in my bundle build 46edd15, but it didn't work when I used the same cmake code in the portfile.cmake. The approach in your link looks cleaner, I'll try that for vcpkg and also refactor the previous approach I used for the bundle (as I don't like the hard-coded Release).

@matlabbe
Copy link
Member

Closing as it now works with C++17.

@mattiasmar
Copy link

@matlabbe: What Dockerfile did you use to test this?

@matlabbe
Copy link
Member

matlabbe commented Jun 11, 2023

@mattiasmar To test latest dependencies, see this docker file: https://github.com/introlab/rtabmap/blob/master/docker/latest_deps/Dockerfile. Note that this docker file is not built in CI (would be too long) and as it is using always latest dependencies, it may fail at some point if dependencies have regressions (if so, open another issue). To build it:

cd rtabmap
docker build -t rtabmap_latest -f docker/latest_deps/Dockerfile .

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

3 participants