Use CGAL and PCL in same project - c++

I am trying to use CGAL and PCL in the same project. Both PCL and CGAL should be installed correctly on my computer, since the examples work.
I created a CMakeList.txt file which references both PCL and CGAL I am able to configure it without the CMake GUI showing any problems, but when I open the project .sln the CGAL includes have errors
for example: Cannot open include file: 'CGAL/Simple_cartesian.h': No such file or directory
All the PCL includes work fine.
If I delete all the PCL references from the CMakeList.txt then the CGAL includes work. I am suspecting that I am doing something wrong in my CMakeList.txt.
Does anyone know what I am doing wrong?
Thank you!
Below is my CMakeList.txt
cmake_minimum_required(VERSION 3.1...3.15)
project(PC_Svr2)
find_package(CGAL QUIET)
if ( CGAL_FOUND )
# create a target per cppfile
file(GLOB cppfiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
foreach(cppfile ${cppfiles})
create_single_source_cgal_program( "${cppfile}" )
endforeach()
else()
message(STATUS "This program requires the CGAL library, and will not be compiled.")
endif()
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (PC_Svr2 cloud_viewer.cpp)
target_link_libraries (PC_Svr2 ${PCL_LIBRARIES})
message("PCL_IO_LIBRARIES - ${PCL_IO_LIBRARIES}")

file(GLOB cppfiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
foreach(cppfile ${cppfiles})
create_single_source_cgal_program( "${cppfile}" )
endforeach()
That is creating a single target from each of the cpp files in CMAKE_CURRENT_SOURCE_DIR. I don't think that is what you want.
If I understand things correctly, your code is in cloud_viewer.cpp, then you should remove the loop and just link with cgal with your target_link_libraries:
target_link_libraries(PCS_Svr2 CGAL::CGAL ${PCL_LIBRARIES})
You can have a look at that page for details.

Related

How can I include aruco library in ros without getting an error in catkin_make

Hello I am trying to use a package that requires the aruco library
I downloaded the lib extracted and executed $ cmake $ make $ sudo make install
No error so far but when I try to do catkin_make on my ros workspace the following error occurs
terminal output
I am new to ROS and generaly cmake files but I think the problem is that the lib has no include directory and both cpp and .h are on the src folder.
Is there a way to fix this?
this is my cmake file for this package
cmake_minimum_required(VERSION 2.8.3)
project(aruco_mapping)
find_package(OpenCV REQUIRED)
find_package(aruco REQUIRED)
find_package(catkin REQUIRED COMPONENTS
roscpp
message_generation
image_transport
cv_bridge
tf
aruco
visualization_msgs
camera_calibration_parsers)
include_directories(${catkin_INCLUDE_DIRS} }
${PROJECT_SOURCE_DIR}/include/)
include_directories(${PROJECT_SOURCE_DIR}/src/)
SET(SOURCES ${PROJECT_SOURCE_DIR}/src/main.cpp
${PROJECT_SOURCE_DIR}/src/aruco_mapping.cpp)
SET(HEADERS ${PROJECT_SOURCE_DIR}/include/aruco_mapping.h)
add_message_files(FILES ArucoMarker.msg)
generate_messages(DEPENDENCIES
std_msgs
geometry_msgs)
catkin_package(
INCLUDE_DIRS include
LIBRARIES
)
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
add_dependencies(${PROJECT_NAME} ${catkin_EXPORTED_TARGETS} aruco_mapping_gencpp )
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} ${aruco_LIBS} ${ROS_LIBRARIES} ${catkin_LIBRARIES})
Can you please help me connect them
While trying to figure it out I realized that the path it was searching for did not exist because I had changed the location of the file through the GUI so it was looking at the wrong path. I just kept the code files and rebuilded the project in a different file and deleted the the previous project, it worked perfectly.
So I would suggest to simply copy the code files and rebuilt the project it only takes a minute. At least this worked for me

proper way to write a CMakeLists referencing HDF5 in Windows

I've already downloaded an built HDF5 under Windows using CMake, I also generated an installer to install it under Program Files.
Below the CMakeLists.txt I wrote to be able to use HDF5 in a program I already wrote under Linux :
cmake_minimum_required(VERSION 2.8)
project(Hdf5DataFeed)
add_definitions(-DWINDOWS)
find_package(HDF5)
FIND_LIBRARY(HDF5_HL_LIBRARY hdf5_hl)
FIND_LIBRARY(ZLIB zlib)
find_library(ZMQ_LIB zmq)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
include_directories(${ZMQ_LIB_INCLUDE})
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${PROJECT_NAME} ${ZLIB} "C:/Program Files/HDF_Group/HDF5/1.10.1/lib/libszip.lib" ${VTK_LIBRARIES} ${ZMQ_LIB} ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARY} Qt5::Core Qt5::Gui Qt5::Widgets)
target_include_directories(${PROJECT_NAME} PRIVATE ${HDF5_INCLUDE_DIRS})
As you can see above, to link HDF5 under Visual Studio, I needed Zlib, Szip (that I had to enter an absolute path to it, I don't like that), HDF5 library and the HDF5 High Level (Lite) library.
These libraries are located under C:\Program Files\HDF_Group\HDF5\1.10.1\lib :
libhdf5.lib <============
libhdf5.settings
libhdf5_cpp.lib
libhdf5_hl.lib <=====
libhdf5_hl_cpp.lib
libhdf5_tools.lib
libszip.lib <=== ????
libzlib.lib <====
I use CMake-Gui to inform CMake of the libraries path (except for Szip, I don't know why CMake doesn't know about it, and why I don't have the possibility to just feed CMake the library directory instead of indicating the path of few of them).
I want to use CMake-GUI to inform CMake of Szip library path, but this last doesn't create an entry of it, I only have these entries related to HDF5 :
I'm having troubles with HDF5 also under Ubuntu (see this question : hdf5.h no such file or directory under Ubuntu and CMake).
For now, it's only under CentOS 7 that I didn't encounter any issues with HDF5.
If someone can give me/us a final solution that works both on Windows and Ubuntu that would be great !
Does this solution work for you?
cmake_minimum_required(VERSION 2.8)
project(Hdf5DataFeed)
# necessary?
add_definitions(-DWINDOWS)
find_package(HDF5 REQUIRED COMPONENTS C CXX HL)
find_package(ZLIB REQUIRED)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
find_library(ZMQ_LIB zmq)
include_directories(${ZMQ_LIB_INCLUDE} ${HDF5_INCLUDE_DIR}
${ZLIB_INCLUDE_DIRS})
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${PROJECT_NAME} ${HDF5_LIBRARIES}
${HDF5_HL_LIBRARIES} ${ZLIB_LIBRARIES} ${VTK_LIBRARIES}
Qt5::Core Qt5::Gui Qt5::Widgets ${ZMQ_LIB})
Recommendation 1: Surely, there is a way to find Qt5 via find_package, i.e.,
find_package(Qt5 COMPONENTS Core Widgets REQUIRED)
and then add the correct variables to include_directories and target_link_libraries. Not sure whether such a possibility exists for the zmq library, though.
Recommendation 2: I think the call the aux_source_directory should be avoided in most cases. Create an explicit list of your source files instead.
For libszip, adding a find_library is better than putting an absolute link to it. For ZLib, it is preferable to use find_library as find_package will require you to feed CMake with an include directory which is not required for HDF5. Finally, it is preferable to use find_package for ZMQ, otherwise, we need to add manually the entry "ZMQ_LIB_INCLUDE".

ROS with QtCreator: autocompletion

I'm using and like QtCreator to code and build my ROS projects written in c++.
Unfortunately the auto-completion for my own header files is not working: e.g. #include "LineTracker.hh"
Building the project works perfectly. And also the auto-completion for other external packages like ros or opencv is working.
Update 2.0: With QtCreator 3.6 the solution is not working
Update 1.0: Found a solution, see bottom!
Thats how my CMakeLists.txt looks:
cmake_minimum_required(VERSION 2.8.3)
project(line_tracking)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(catkin REQUIRED COMPONENTS
roscpp
tf
sensor_msgs
image_transport
cv_bridge
)
catkin_package()
include_directories(
include
${catkin_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}
)
add_executable(${PROJECT_NAME}
src/line_tracking.cpp
src/EDLineDetector.cpp
src/LineTracker.cpp
)
target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
)
# --- QT CREATOR STUFF ---
#Add all files in subdirectories of the project in
# a dummy_target so qtcreator has access to all files
FILE(GLOB children ${CMAKE_SOURCE_DIR}/*)
FOREACH(child ${children})
IF(IS_DIRECTORY ${child})
file(GLOB_RECURSE dir_files "${child}/*")
LIST(APPEND extra_files ${dir_files})
ENDIF()
ENDFOREACH()
add_custom_target(dummy_${PROJECT_NAME} SOURCES ${extra_files})
#
The file/package structure looks standard like this:
CMakeLists.txt
|
+ -- src
|
+ -- include
How do I have to adapt my CMakeLists.txt that QtCreator finds my headers for autocompletion?
Thank you very much for your help!
Sidenote:
When I use the top CMakeLists.txt file of the catkin workspace in QtCeator and I include the header files under their package path like this: #include <packageName/include/headerFile.h> the auto-completion is working but the build is not working anymore. So this is only a bad and not userfriendly hack to get auto-completion during coding.
Update 1.0:
I found a solution which is working:
I create a library from all the (class) files which have header files, and link the library to the main file, instead of adding the files as executables. I posted it here as answer.
But I don't know why it is working like this and not without the way over the library. Any explanations?
Update 2.0:
I just upgraded to QtCreator 3.6 and there my solution with the library in not working anymore.
Does anybody know another solution?!
Update: This solution does NOT work with QtCreator 3.6
I found a solution to my own question. Not so much fun, but anyway, I spent a lot of time with that issue so here the solution, which is hopefully useful for others:
Auto-completion with CMakeLists.txt in QtCreator 3.5.1 for your own classes:
Create a library with all your classes: ADD_LIBRARY(myFilesLib src/class1.cpp ...)
Add your executable (main function): add_executable(${PROJECT_NAME} src/main.cpp)
Link your library to your executable: target_link_libraries(${PROJECT_NAME} myFilesLib)
With this way over the library, auto-completion is working in QtCreator!
For ROS (catkin) don't forget to link the ${catkin_LIBRARIES}.
Here the whole CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.3)
project(example_project)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(catkin REQUIRED COMPONENTS
roscpp
)
catkin_package()
include_directories(
include
${catkin_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}
)
# Create a library with all your classes
add_library(myFilesLib
src/class1.cpp
src/class2.cpp
src/class3.cpp
)
target_link_libraries(myFilesLib
${catkin_LIBRARIES}
)
# add your executable
add_executable(${PROJECT_NAME}
src/main.cpp
)
# link the library with your classes to the executable
target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
myFilesLib
)
I don't know why it is working only with the way over the library but it is working. Maybe somebody has an explanation?!
This is really annoying. Finally I figured out a solution, that works at Qt Creator 4.1.0, and probably works at other versions.
Write your include_directories correctly, so that compilation is OK.
Below the include_directories, add the following line. Note that the sequence matters, the following line must locate below the include_directories.
file(GLOB_RECURSE HEADERS */*.hpp */*.h)
Add ${HEADERS} # for qtcreator... in one of your add_executable. like:
add_executable(slam_pp_node
${HEADERS} # for qtcreator...
src/***.cpp
)
The above should be enough to solve the autocompletion problem. If not, add the following lines at the end of your CMakeList.txt:
file(GLOB_RECURSE EXTRA_FILES */*)
add_custom_target(${PROJECT_NAME}_OTHER_FILES ALL WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} SOURCES ${EXTRA_FILES})
Good luck!

Using Qt inside Clion

I'm trying to use Clion IDE to compile a simple program using Qt library, but I can't figure out how to configure CMakeLists.txt file. (I'm not familiar with cmake and toolchain)
this is my current CMakeLists.txt file:
cmake_minimum_required(VERSION 3.2)
project(MyTest)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(MyTest ${SOURCE_FILES})
# Define sources and executable
set(EXECUTABLE_NAME "MySFML")
add_executable(${EXECUTABLE_NAME} main.cpp)
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
endif()
It's configured to use SFML library with a "FindSFML.cmake" file and it works fine. (I have copied these files from some tutorial) now I want some help regarding proper CMakeLists.txt configuration to compile programs that are using Qt library (it's more helpful if the files and explanations are provided).
P.S: my current OS is manjaro 0.8.13 and all I could find was explaining configurations in windows environment so I was unable to implement those tutorials.
In addition to #tomvodi's answer, you can use a simpler syntax :
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui).
Then, you don't call qt5_use_modules but instead use the standard command to link :
target_link_libraries(MyTest Qt5::Core Qt5::Widgets Qt5::Gui)
Your CMake project file is missing the Qt packages. You have to add:
find_package( Qt5Core REQUIRED )
find_package( Qt5Widgets REQUIRED )
find_package( Qt5Gui REQUIRED )
and then
qt5_use_modules( MyTest Core Widgets Gui )

find-package to a development library using CMAKE

This is a total cmake noob question I'm sure.
I'm working on an OpenCV project and wish to test something using the latest beta release. How can I specify the beta libraries without installing them onto my system? My beta opencv has been successfully built in:
/Users/paul/hacking/robotics/opencv/build/lib/
My current cmake has basically been lifted from the opencv samples and looks like this:
# cmake for Stereo Vision App
# your opencv/build directory should be in your system PATH
# set minimum required version for cmake
cmake_minimum_required(VERSION 2.8)
# define the project name
set(project_name "Stereo")
# set the project namee
project("${project_name}")
# add opencv package to the project
find_package( OpenCV REQUIRED )
MESSAGE("OpenCV version : ${OpenCV_VERSION}")
# add opencv include directories to the project
include_directories( ${OpenCV_INCLUDE_DIRS} )
# add include directory
include_directories (${Stereo_SOURCE_DIR})
# add library
add_library( CameraCalibrator CameraCalibrator.cpp)
# add executable
#add_executable( videoprocessing videoprocessing.cpp)
#add_executable( tracking tracking.cpp)
#add_executable( foreground foreground.cpp)
add_executable( calibrate calibrate.cpp)
add_executable( rightsideup rightsideup.cpp)
add_executable( live live.cpp)
add_executable( live2 live2.cpp)
add_executable( stereo-tune stereo-tune.cpp)
add_executable( project project.cpp)
add_executable( stereo_calibrate stereo_calibrate.cpp)
add_executable( capture_two_camera_chessboards capture_two_camera_chessboards.cpp)
add_executable( capture_stereo_chessboards capture_stereo_chessboards.cpp)
# link libraries
#target_link_libraries( videoprocessing ${OpenCV_LIBS})
#target_link_libraries( tracking ${OpenCV_LIBS})
#target_link_libraries( foreground ${OpenCV_LIBS})
target_link_libraries( rightsideup ${OpenCV_LIBS})
target_link_libraries( live ${OpenCV_LIBS})
target_link_libraries( live2 ${OpenCV_LIBS})
target_link_libraries( stereo-tune ${OpenCV_LIBS})
target_link_libraries( project ${OpenCV_LIBS})
target_link_libraries( stereo_calibrate ${OpenCV_LIBS})
target_link_libraries( capture_two_camera_chessboards ${OpenCV_LIBS})
target_link_libraries( capture_stereo_chessboards ${OpenCV_LIBS})
target_link_libraries( calibrate ${OpenCV_LIBS} CameraCalibrator)
I've tried using link_libraries and setting the version on the find package line to 3.0, however it always finds the system installed libraries 2.4.10
Edit 1:
cmake -DPCL_DIR:PATH="../../pcl/build" -DOpenCV_DIR:PATH="../../opencv/build" ..
Is not working for me for some reason. Likewise when I try to set these variables inside the CMake script it also does not work.
set(PCL_DIR "../../pcl/build" CACHE PATH "")
set(OpenCV_DIR "../../opencv/build" CACHE PATH "")
Many thanks!
Paul
You're going in the right direction. cmake's Find scripts look in the standard system paths first unless told otherwise. Each FIND script has its own set of cmake variables which you can set to alter the behaviour.
For FindOpenCV.cmake it seems to be OPENCV_BASE_DIR.
Here's a link to some source code:
https://github.com/rpavlik/cmake-modules/blob/master/FindOpenCV.cmake
Edit:
I don't fully understand, but the following seems to work with absolute paths
set(OpenCV_DIR "/Users/paul/hacking/robotics/opencv/build" CACHE PATH "")
set(PCL_DIR "/Users/paul/hacking/robotics/pcl/build" CACHE PATH "")
set(VTK_DIR "/Users/paul/hacking/robotics/VTK/build" CACHE PATH "")
At least less things to go wrong if I get the command line wrong, I no longer need to remember to do the following:
OpenCV_DIR=../../opencv/build cmake ..
In the PCL documentation it says to use:
set(PCL_DIR "/path/to/PCLConfig.cmake")
But this doesn't work for me.