Target link multiple libraries in a project on clion - c++

I am trying to use target_link_libraries in a project on clion, but when i run the project the following error is printed:
/usr/bin/ld: cannot find -lctop_common
/usr/bin/ld: cannot find -lctop_log
/usr/bin/ld: cannot find -lctop_util
/usr/bin/ld: cannot find -leigen
/usr/bin/ld: cannot find -lcrl
/usr/bin/ld: cannot find -lcrl-algorithm
/usr/bin/ld: cannot find -lcrl-loader
/usr/bin/ld: cannot find -lcrl-tsplib
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
This is what my cmakelist file includes:
cmake_minimum_required(VERSION 2.8.3)
project(planner_standalone_grasp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-diagnostics-color")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
# find all cpp files in currect directory (where CMakeLists.txt is)
file(GLOB SOURCE_FILES FILES_MATCHING PATTERN "./src/*.cpp")
include_directories(src)
add_executable(${PROJECT_NAME} main.cpp ${SOURCE_FILES})
set(EXE_LIBS
ctop_common
ctop_log
ctop_util
eigen
crl
crl-algorithm
crl-loader
crl-tsplib
yaml-cpp
)
target_link_libraries(${PROJECT_NAME} ${EXE_LIBS})
... Any help would be highly appreciated.

target_link_libraries tells cmake what libraries to link against (the -l flag that is). You have to specify where to find said libraries too! this can be done with target_link_directories... (the -L flag).
If you have these libraries in the lib folder, make sure they are compiled for the same platform as the executable you are trying to build.
I believe on linux you can also drop the libraries in the lib folder and not use the target_link_directories inc make, not sure...
so:
target_link_libraries specifies the names of the libraries,
target_link_directories specifies the directories of these libraries.

Related

Target link Eigen library on Clion fails

I am trying to link eigen to my project on clion, but the following error is printed:
This is my cmakelist file with all the attempts to link the library:
cmake_minimum_required(VERSION 2.8.3)
project(planner_standalone_grasp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-diagnostics-color")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
# find all cpp files in currect directory (where CMakeLists.txt is)
file(GLOB SOURCE_FILES FILES_MATCHING PATTERN "./src/*.cpp")
include_directories(src)
add_executable(${PROJECT_NAME} main.cpp ${SOURCE_FILES})
set(EXE_LIBS
ctop_common
ctop_log
ctop_util
eigen
crl
crl-algorithm
crl-loader
crl-tsplib
yaml-cpp
)
target_link_directories(${PROJECT_NAME} PUBLIC lib/comrob/lib/)
target_link_directories(${PROJECT_NAME} PUBLIC ctop/common/cmake-build-debug/)
target_link_directories(${PROJECT_NAME} PUBLIC ctop/log/cmake-build-debug/)
target_link_directories(${PROJECT_NAME} PUBLIC ctop/util/cmake-build-debug/)
set(EIGEN_DIR "/usr/local/include/Eigen/")
include_directories(${EIGEN_DIR})
find_package (Eigen3 3.3 REQUIRED NO_MODULE)
target_link_libraries (${PROJECT_NAME} Eigen3::Eigen)
target_link_directories(${PROJECT_NAME} PUBLIC lib/eigen/Eigen/)
target_link_directories(${PROJECT_NAME} PUBLIC /usr/local/include/Eigen/)
target_link_directories(${PROJECT_NAME} PUBLIC /usr/local/include/eigen3/Eigen/)
target_link_libraries(${PROJECT_NAME} ${EXE_LIBS})
All other libraries in the project are successfully linked except Eigen - This is the error message:
[6/6] Linking CXX executable planner_standalone_grasp
FAILED: planner_standalone_grasp
: && /usr/bin/c++ -O0 -fno-diagnostics-color -std=c++17 -g -rdynamic CMakeFiles/planner_standalone_grasp.dir/main.cpp.o CMakeFiles/planner_standalone_grasp.dir/src/Grasp.cpp.o CMakeFiles/planner_standalone_grasp.dir/src/WallEdge.cpp.o CMakeFiles/planner_standalone_grasp.dir/src/WallGraph.cpp.o CMakeFiles/planner_standalone_grasp.dir/src/pt2eigen.cpp.o -o planner_standalone_grasp -L/home/sim/CLionProjects/Test/lib/comrob/lib -L/home/sim/CLionProjects/Test/ctop/common/cmake-build-debug -L/home/sim/CLionProjects/Test/ctop/log/cmake-build-debug -L/home/sim/CLionProjects/Test/ctop/util/cmake-build-debug -L/home/sim/CLionProjects/Test/lib/eigen/Eigen -L/usr/local/include/Eigen -L/usr/local/include/eigen3/Eigen -Wl,-rpath,/home/sim/CLionProjects/Test/lib/comrob/lib:/home/sim/CLionProjects/Test/ctop/common/cmake-build-debug:/home/sim/CLionProjects/Test/ctop/log/cmake-build-debug:/home/sim/CLionProjects/Test/ctop/util/cmake-build-debug:/home/sim/CLionProjects/Test/lib/eigen/Eigen:/usr/local/include/Eigen:/usr/local/include/eigen3/Eigen -lctop_common -lctop_log -lctop_util -leigen -lcrl -lcrl-algorithm -lcrl-loader -lcrl-tsplib -lyaml-cpp && :
/usr/bin/ld: cannot find -leigen
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Any help would be highly appreciated!
In my experience there is two possible causes for this issue:
there is no library named libeigen. in the provided directories (the ones in target_link_directories). Perhaps the path is wrong?
You should know that usually library files are not located in the include directories of a repository...
there is a library named as such, though it was compiled for the wrong platform... i.e. a library compiled for linux cannot be linked if you are making an executable for windows. Usually you can find the source code and compile it yourself.
Hope this helps.

linker can't find libraries although defined in CMakeLists.txt

I'm quite new to work with cmake, and there is a problem I can't find the solution to:
I use the vtk library and specify this in the CMakeLists.txt file:
cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
cmake_policy(SET CMP0053 OLD)
project (pcl-visualizer)
find_package (Qt4 REQUIRED)
find_package (VTK REQUIRED)
find_package (PCL 1.7.1 REQUIRED)
include_directories (${PCL_INCLUDE_DIRS})
link_directories (${PCL_LIBRARY_DIRS})
add_definitions (${PCL_DEFINITIONS})
set (project_SOURCES main.cpp pclviewer.cpp)
set (project_HEADERS pclviewer.h)
set (project_FORMS pclviewer.ui)
set (VTK_LIBRARIES vtkRendering vtkGraphics vtkHybrid QVTK)
QT4_WRAP_CPP (project_HEADERS_MOC ${project_HEADERS})
QT4_WRAP_UI (project_FORMS_HEADERS ${project_FORMS})
INCLUDE (${QT_USE_FILE})
ADD_DEFINITIONS (${QT_DEFINITIONS})
ADD_EXECUTABLE (pcl_visualizer ${project_SOURCES}
${project_FORMS_HEADERS}
${project_HEADERS_MOC})
TARGET_LINK_LIBRARIES (pcl_visualizer ${QT_LIBRARIES} ${PCL_LIBRARIES} ${VTK_LIBRARIES})
cmake also runs fine. It gives no error so I assume it can find all libraries, including the vtk library?
When I run make though, I get this error message:
[ 16%] Linking CXX executable pcl_visualizer
/usr/bin/ld: cannot find -lvtkRendering
/usr/bin/ld: cannot find -lvtkGraphics
/usr/bin/ld: cannot find -lvtkHybrid
/usr/bin/ld: cannot find -lQVTK
/usr/bin/ld: cannot find -lvtkRendering
/usr/bin/ld: cannot find -lvtkGraphics
/usr/bin/ld: cannot find -lvtkHybrid
/usr/bin/ld: cannot find -lQVTK
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/pcl_visualizer.dir/build.make:410: pcl_visualizer] Error 1
make[1]: *** [CMakeFiles/Makefile2:68: CMakeFiles/pcl_visualizer.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I installed the vtk library via the package manager (pacman, I run arch linux), so it should be in one of the standard directories?
I checked if the right libraries are installed via pacman -Q vtk and it lists all needed libraries in the `/usr/lib/`` directory.

How to correct CMAKE error: package 'opencv' not found

OK, I know that opencv linking has been discussed before, but I can't see an error and I don't understand the corrective action. I'm trying to link DBoW2 library, which requires opencv. I'm getting undefined reference errors.
$ mingw32-make
Linking CXX shared library ..\lib\libDBoW2.dll
CMakeFiles\DBoW2.dir/objects.a(FORB.cpp.obj):FORB.cpp:(.text+0x124): undefined reference to `cv::Mat::zeros(int, int, int)'
CMakeFiles\DBoW2.dir/objects.a(FORB.cpp.obj):FORB.cpp:(.text+0x1db): undefined reference to `cv::fastFree(void*)'
CMakeFiles\DBoW2.dir/objects.a(FORB.cpp.obj):FORB.cpp:(.text+0x394): undefined reference to `cv::Mat::deallocate()'
CMakeFiles\DBoW2.dir/objects.a(FORB.cpp.obj):FORB.cpp:(.text+0x46a): undefined reference to `cv::Mat::copyTo(cv::_OutputArray const&) const'
CMakeFiles\DBoW2.dir/objects.a(FORB.cpp.obj):FORB.cpp:(.text+0x503): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
CMakeFiles\DBoW2.dir/objects.a(FORB.cpp.obj):FORB.cpp:(.text+0x93f): undefined reference to `cv::Mat::create(int, int const*, int)'
collect2.exe: error: ld returned 1 exit status
Here's the CMakeLists.txt file
cmake_minimum_required(VERSION 2.8)
project(DBoW2)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 -march=native ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 -march=native")
set(HDRS_DBOW2
DBoW2/BowVector.h
DBoW2/FORB.h
DBoW2/FClass.h
DBoW2/FeatureVector.h
DBoW2/ScoringObject.h
DBoW2/TemplatedVocabulary.h)
set(SRCS_DBOW2
DBoW2/BowVector.cpp
DBoW2/FORB.cpp
DBoW2/FeatureVector.cpp
DBoW2/ScoringObject.cpp)
set(HDRS_DUTILS
DUtils/Random.h
DUtils/Timestamp.h)
set(SRCS_DUTILS
DUtils/Random.cpp
DUtils/Timestamp.cpp)
find_package(OpenCV REQUIRED)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
include_directories(${OpenCV_INCLUDE_DIRS})
add_library(DBoW2 SHARED ${SRCS_DBOW2} ${SRCS_DUTILS})
target_link_libraries(DBoW2 ${OpenCV_LIBS})
I'm using the gui interface, and the parameter OpenCV_DIR automatically sets to C:/OpenCV/minwg_64. Under that directory there is a directory lib containing library files like "libopencv_videostab300.dll.a"
The CMakeCache.txt file contains the lines
//Dependencies for the target
DBoW2_LIB_DEPENDS:STATIC=general;opencv_videostab;general;opencv_videoio;general;opencv_video;general;opencv_superres;general;opencv_stitching;general;opencv_shape;general;opencv_photo;general;opencv_objdetect;general;opencv_ml;general;opencv_imgproc;general;opencv_imgcodecs;general;opencv_highgui;general;opencv_hal;general;opencv_flann;general;opencv_features2d;general;opencv_core;general;opencv_calib3d;
From what I've read, the following lines should be sufficient, but I'm getting the linker errors.
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(DBoW2 ${OpenCV_LIBS})
Edit 1:
In response to Chris Maes
added the pkg check
pkg_check_modules (OPENCV REQUIRED opencv)
Now the configure causes an error, which is progress, but I'm still at a loss. I must have an error in the opencv installation / build. I do have a second copy on an external drive, that was built recently (and easily) using something like cmake .. . But setting OpenCV_DIR to the external build produces the same error.
Found PkgConfig: C:/msys64/usr/bin/pkg-config.exe (found version "0.28")
checking for module 'opencv'
package 'opencv' not found
Edit 2:
Here are the settings that CMake automatically generates when I start a new cache and press generate twice (first time it only generates the make, sh).
CMAKE_BUILD_TYPE (BLANK)
CMAKE_GNUtoMS (UNCHECKED)
CMAKE_INSTALL_PREFIX C:/Program Files (x86)/DBoW2
CMAKE_MAKE_PROGRAM C:/msys64/mingw64/bin/mingw32-make.exe
CMAKE_SH C:/msys64/usr/bin/sh.exe
OpenCV_DIR C:/OpenCV/minwg_64
The directory C:/OpenCV/minwg_64 contains the opencv library built from mingw gcc 64, and cmake files including OpenCVConfig.cmake and directories bin and lib. I wonder if I need directory staticlib?
For windows environment, I have
OPENCV_DIR = C:\OpenCV\minwg_64 (where built bin and lib are located)
OPENCV_VER = 300
PATH includes C:\OpenCV\minwg_64\bin
On linux I use pkg_check_modules plugin for cmake:
find_package( OpenCV REQUIRED )
find_package( PkgConfig REQUIRED )
pkg_check_modules (OPENCV REQUIRED opencv)
include_directories(/usr/include/opencv2)
target_link_libraries(DBoW2 ${OPENCV_LDFLAGS})
note: I don't remember why I used hardcoded /usr/include/opencv2, but I guess OPENCV_INCLUDE_DIRS wasn't any good when I tried. There might be a more clean way :)

link path confusion after target_link_libraries call

I have a cmake project where I want to add a class containing the matlab engine. For compiling it I need to include two libraries eng and mx, which I do by adding
target_link_libraries( ${TARGET} /usr/local/MATLAB/R2013b/bin/glnxa64/libeng.so)
target_link_libraries( ${TARGET} /usr/local/MATLAB/R2013b/bin/glnxa64/libmx.so)
to my CMakeLists.txt file.
However there are also lots of other old versions of libraries in /usr/local/MATLAB/R2013b/bin/glnxa64/, which seem
to be automatically added to the path as well when calling the above command. I think this causes the compiler to not find my
normal libraries anymore and produces an error.
How can I include only the two above libraries, and not all the others in the glnxa64 folder?
The warning shown after running cmake . :
CMake Warning at CMakeLists.txt:23 (add_executable):
Cannot generate a safe runtime search path for target CCDWidget because
files in some directories may conflict with libraries in implicit
directories:
runtime library [libboost_program_options.so.1.49.0] in /usr/lib may be hidden by files in:
/usr/local/MATLAB/R2013b/bin/glnxa64
runtime library [libboost_system.so.1.49.0] in /usr/lib may be hidden by files in:
/usr/local/MATLAB/R2013b/bin/glnxa64
runtime library [libboost_filesystem.so.1.49.0] in /usr/lib may be hidden by files in:
/usr/local/MATLAB/R2013b/bin/glnxa64
runtime library [libboost_regex.so.1.49.0] in /usr/lib may be hidden by files in:
/usr/local/MATLAB/R2013b/bin/glnxa64
Some of these libraries may not be found correctly.
And the error message during linking:
Linking CXX executable CCDWidget
/usr/lib/x86_64-linux-gnu/libharfbuzz.so.0: undefined reference to `FT_Face_GetCharVariantIndex'
/usr/lib/x86_64-linux-gnu/libharfbuzz.so.0: undefined reference to `FT_Get_Advance'
collect2: error: ld returned 1 exit status
make[2]: *** [CCDWidget] Error 1
make[1]: *** [CMakeFiles/CCDWidget.dir/all] Error 2
make: *** [all] Error 2
Below is my full CMakeLists.txt file. Lines commented out with two ## are alternatives that I tried before and didn't solve my problem.
I also added LINK_PRIVATE to the target_link_libraries command as shown in the code below, which didn't make a difference.
The option PRIVATE alone seems to be not accepted by my cmake version, as it changed the error meassage to
/usr/bin/ld: cannot find -lPRIVATE
collect2: error: ld returned 1 exit status
When the #eng line is commented out, the compilation and linking works without errors
(when calling the matlab engine is also commented out in Readout.cpp), so the error must be produced by that line.
#Specify the version being used as well as the language
cmake_minimum_required(VERSION 2.6)
##cmake_policy(SET CMP0003 NEW)
#Name your project here
project(CCDWidget)
set(TARGET CCDWidget)
set(MAIN_SOURCES CCDWidget.cpp main.cc CCDControl.cpp VideoWindow.cpp ImageWindow.cpp ThisMeasurement.cpp KineticSeries.cpp FastKinetics.cpp Readout.cpp)
##SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
#set_source_files_properties(Readout.cpp PROPERTIES COMPILE_FLAGS "-I/usr/local/MATLAB/R2013b/extern/include -I/usr/local/MATLAB/R2013b/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -I/usr/local/MATLAB/R2013b/extern/include/cpp -I/usr/local/MATLAB/R2013b/extern/include -DGLNXA64 -DGCC -DMX_COMPAT_32 -DNDEBUG -Wno-effc++")
find_package(Boost COMPONENTS program_options system filesystem regex REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTKMM gtkmm-3.0)
include_directories( ${GTKMM_INCLUDE_DIRS} )
include_directories( ${Boost_INCLUDE_DIR} )
include_directories( ${PROJECT_SOURCE_DIR} )
##link_directories(/usr/local/MATLAB/R2013b/bin/glnxa64)
##target_link_libraries( ${TARGET} eng)
##target_link_libraries( ${TARGET} mx)
set(CMAKE_CXX_FLAGS "--std=c++11")
add_executable( ${TARGET} ${MAIN_SOURCES} )
target_link_libraries( ${TARGET} ${GTKMM_LIBRARIES} )
target_link_libraries( ${TARGET} ${Boost_LIBRARIES} )
target_link_libraries( ${TARGET} LINK_PRIVATE /usr/local/MATLAB/R2013b/bin/glnxa64/libeng.so) # eng
#target_link_libraries( ${TARGET} LINK_PRIVATE /usr/local/MATLAB/R2013b/bin/glnxa64/libmx.so ) # mx
target_link_libraries( ${TARGET} andor )
You could try using an imported target:
add_library(eng SHARED IMPORTED)
set_property(TARGET eng PROPERTY IMPORTED_LOCATION /usr/local/MATLAB/R2013b/bin/glnxa64/libeng.so)
...
add_executable( ${TARGET} ${MAIN_SOURCES} )
...
target_link_libraries(${TARGET} eng)
For debugging you could try to build with "make VERBOSE=1".
This will show you the used gcc command line.
CMake probably transforms your target_link_libraries command to something like:
g++ ... -L/usr/local/MATLAB/R2013b/bin/glnxa64 -leng ...
gcc then finds some boost libraries in this folder.

Problems setting up gsl with cmake

I was able to successfully configure and generate the build folder (KinectSLAM6D/build.). However, when I try to build it using make, I got an error saying gsl is not found. I am pretty sure this is just a configuration issue as I have gsl installed (they're in usr/local), but I am unable to configure it. I have tried adding the following lines to CMakeList:
include_directories(${GSL_INCLUDE_DIRS} ${GSLCBLAS_INCLUDE_DIRS})
set(LIBS ${LIBS} ${GSL_LIBRARIES} ${GSLCBLAS_LIBRARIES})
I have copied the pertinent output below. I have found a couple of answers to compiling with gsl (adding -lgsl). However, I have no clue where to put that in CMakeLists or the generated MakeList and MakeList2 files.
Here's the generated output.
....
[ 44%] Building CXX object CMakeFiles/Kinect6DSLAM.dir/src/GraphOptimizer_G2O.cpp.o
[ 45%] Building CXX object CMakeFiles/Kinect6DSLAM.dir/src/CKinect2DRawlog.cpp.o
Linking CXX executable Kinect6DSLAM
/usr/bin/ld: warning: libopencv_core.so.2.3, needed by /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libmrpt-base.so, may conflict with libopencv_core.so.2.4
/usr/bin/ld: warning: libopencv_imgproc.so.2.3, needed by /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libmrpt-base.so, may conflict with libopencv_imgproc.so.2.4
/usr/bin/ld: warning: libopencv_highgui.so.2.3, needed by /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libmrpt-base.so, may conflict with libopencv_highgui.so.2.4
../gicp/libgicp.a(gicp.o): In function `dgc::gicp::GICPPointSet::ComputeMatrices()':
gicp.cpp:(.text+0x462): undefined reference to `gsl_vector_alloc'
gicp.cpp:(.text+0x470): undefined reference to `gsl_vector_alloc'
... a bunch more undefined references to gsl
collect2: ld returned 1 exit status
make[2]: *** [Kinect6DSLAM] Error 1
make[1]: *** [CMakeFiles/Kinect6DSLAM.dir/all] Error 2
make: *** [all] Error 2
This if the full CMakeList.txt. I am trying to run Miguel Algaba's SLAM project.
PROJECT(KinectSLAM6D)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW) # Required by CMake 2.7+
endif(COMMAND cmake_policy)
# Set the output directory for the build executables
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build)
#Add here your project dependencies
FIND_PACKAGE(MRPT REQUIRED hwdrivers maps graphslam) #Add here your project dependencies
FIND_PACKAGE(PCL REQUIRED)
FIND_PACKAGE(OpenCV REQUIRED )
INCLUDE_DIRECTORIES(${PCL_INCLUDE_DIRS})
LINK_DIRECTORIES(${PCL_LIBRARY_DIRS})
ADD_DEFINITIONS(${PCL_DEFINITIONS})
# Required by StanfordGICP
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
FIND_PACKAGE(GSL REQUIRED)
include_directories(${GSL_INCLUDE_DIRS} ${GSLCBLAS_INCLUDE_DIRS})
set(LIBS ${LIBS} ${GSL_LIBRARIES} ${GSLCBLAS_LIBRARIES})
FIND_PACKAGE(Boost COMPONENTS system program_options REQUIRED)
include_directories(${PROJECT_SOURCE_DIR}/gicp)
include_directories(${PROJECT_SOURCE_DIR}/gicp/ann_1.1.1/include/ANN)
# G2O library
# Set up the top-level include directories
SET( G2O_INCLUDE ${PROJECT_SOURCE_DIR}/EXTERNAL/g2o CACHE PATH "Directory of G2O")
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR} ${G2O_INCLUDE})
# Add g2o lib dir
LINK_DIRECTORIES( ${LINK_DIRECTORIES} "${G2O_INCLUDE}/lib" )
#Generate config.h
configure_file(g2o/trunk/config.h.in ${PROJECT_BINARY_DIR}/g2o/config.h)
include_directories(${PROJECT_BINARY_DIR})
INSTALL(FILES ${PROJECT_BINARY_DIR}/g2o/config.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/g2o)
# Include the subdirectories
ADD_SUBDIRECTORY(g2o/trunk)
INCLUDE_DIRECTORIES(${CSPARSE_INCLUDE_DIR}) #You can use CPARSE or CHOLMOD
INCLUDE_DIRECTORIES(${CHOLMOD_INCLUDE_DIR})
set(G2O_DIR ${PROJECT_SOURCE_DIR}/g2o/trunk)
include_directories(${G2O_DIR})
link_directories(${G2O_DIR}/lib)
# Declare the target (an executable)
ADD_EXECUTABLE(Kinect6DSLAM kinect6DSLAM.cpp
./include/KinectGrabber.h
./include/KinectGrabber_OpenNI.h
./src/KinectGrabber_OpenNI.cpp
./include/KinectGrabber_Rawlog.h
./src/KinectGrabber_Rawlog.cpp
./include/KinectGrabber_Rawlog2.h
./src/KinectGrabber_Rawlog2.cpp
./include/KinectGrabber_MRPT.h
./src/KinectGrabber_MRPT.cpp
./include/VisualFeatureDescriptorExtractor.h
./include/VisualFeatureDescriptorExtractor_SURF_GPU.h
./include/VisualFeatureDescriptorExtractor_Generic.h
./include/VisualFeatureDescriptorExtractor_ORB.h
./include/VisualFeatureMatcher.h
./include/VisualFeatureMatcher_Generic.h
./include/PointCloudViewer.h
./include/PointCloudViewer_MRPT.h
./src/VisualFeatureDescriptorExtractor_SURF_GPU.cpp
./src/VisualFeatureDescriptorExtractor_Generic.cpp
./src/VisualFeatureDescriptorExtractor_ORB.cpp
./src/VisualFeatureMatcher_Generic.cpp
./src/PointCloudViewer_MRPT.cpp
./include/Visual3DRigidTransformationEstimator.h
./include/Visual3DRigidTransformationEstimator_SVD.h
./src/Visual3DRigidTransformationEstimator_SVD.cpp
./include/Visual3DRigidTransformationEstimator_RANSAC.h
./src/Visual3DRigidTransformationEstimator_RANSAC.cpp
./include/ICPPoseRefiner.h
./include/ICPPoseRefiner_PCL.h
./src/ICPPoseRefiner_PCL.cpp
./include/ICPPoseRefiner_StanfordGICP.h
./src/ICPPoseRefiner_StanfordGICP.cpp
./include/Miscellaneous.h
./src/Miscellaneous.cpp
./include/FrameRGBD.h
./src/FrameRGBD.cpp
./include/PointCloudDownsampler.h
./src/PointCloudDownsampler.cpp
./include/KeyframeLoopDetector.h
./src/KeyframeLoopDetector.cpp
./include/GraphOptimizer.h
./include/GraphOptimizer_MRPT.h
./src/GraphOptimizer_MRPT.cpp
./include/GraphOptimizer_G2O.h
./src/GraphOptimizer_G2O.cpp
./include/CKinect2DRawlog.h
./src/CKinect2DRawlog.cpp
)
TARGET_LINK_LIBRARIES(Kinect6DSLAM ${MRPT_LIBS}
${PCL_LIBRARIES}
${OpenCV_LIBS}
${Boost_LIBRARIES}
#GICP
${GSL_LIBRARIES}
${PROJECT_SOURCE_DIR}/gicp/ann_1.1.1/lib/libANN.a
${PROJECT_SOURCE_DIR}/gicp/libgicp.a
#G2O
core math_groups types_slam3d
solver_csparse #You can use CPARSE or CHOLMOD
solver_cholmod ${CHOLMOD_LIBRARIES}
)
# Declare the target (an executable)
ADD_EXECUTABLE(PairwiseAlignmentSteps PairwiseAlignmentSteps.cpp
./include/KinectGrabber.h
./include/KinectGrabber_OpenNI.h
./src/KinectGrabber_OpenNI.cpp
./include/KinectGrabber_Rawlog.h
./src/KinectGrabber_Rawlog.cpp
./include/KinectGrabber_MRPT.h
./src/KinectGrabber_MRPT.cpp
./include/VisualFeatureDescriptorExtractor.h
./include/VisualFeatureDescriptorExtractor_SURF_GPU.h
./include/VisualFeatureDescriptorExtractor_Generic.h
./include/VisualFeatureDescriptorExtractor_ORB.h
./include/VisualFeatureMatcher.h
./include/VisualFeatureMatcher_Generic.h
./include/PointCloudViewer.h
./include/PointCloudViewer_MRPT.h
./src/VisualFeatureDescriptorExtractor_SURF_GPU.cpp
./src/VisualFeatureDescriptorExtractor_Generic.cpp
./src/VisualFeatureDescriptorExtractor_ORB.cpp
./src/VisualFeatureMatcher_Generic.cpp
./src/PointCloudViewer_MRPT.cpp
./include/Visual3DRigidTransformationEstimator.h
./include/Visual3DRigidTransformationEstimator_SVD.h
./src/Visual3DRigidTransformationEstimator_SVD.cpp
./include/Visual3DRigidTransformationEstimator_RANSAC.h
./src/Visual3DRigidTransformationEstimator_RANSAC.cpp
./include/ICPPoseRefiner.h
./include/ICPPoseRefiner_PCL.h
./src/ICPPoseRefiner_PCL.cpp
./include/ICPPoseRefiner_StanfordGICP.h
./src/ICPPoseRefiner_StanfordGICP.cpp
./include/Miscellaneous.h
./src/Miscellaneous.cpp
./include/FrameRGBD.h
./src/FrameRGBD.cpp
./include/PointCloudDownsampler.h
./src/PointCloudDownsampler.cpp
)
TARGET_LINK_LIBRARIES(PairwiseAlignmentSteps ${MRPT_LIBS}
${PCL_LIBRARIES}
${OpenCV_LIBS}
${Boost_LIBRARIES}
#GICP
${GSL_LIBRARIES}
${PROJECT_SOURCE_DIR}/gicp/ann_1.1.1/lib/libANN.a
${PROJECT_SOURCE_DIR}/gicp/libgicp.a
)
# Set optimized building:
IF(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_BUILD_TYPE MATCHES "Debug")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -mtune=native")
ENDIF(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_BUILD_TYPE MATCHES "Debug")
target_link_libraries(Kinect6DSLAM ${LIBS})
Something tells me, that adding target_link_libraries(Kinect6DSLAM ${LIBS}) will help you.
Also, instead of constructs like
set(VAR ${VAR} somethingelse)
you can use this:
list(APPEND VAR somethingelse)