OpenCV and Gtest conflict in CMake - c++

I am trying to do some Google Tests on my application and I met some conflicts between OpenCV and GTest:
/usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib/libgtest.a(gtest-all.cc.o): In function `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)':
gtest-all.cc:(.text+0xdd84): multiple definition of `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)'
/usr/local/lib/libopencv_ts.a(ts_gtest.cpp.o):ts_gtest.cpp:(.text._ZN7testing8internal8GTestLogC2ENS0_16GTestLogSeverityEPKci+0x0): first defined here
...
The GTest is used in opencv_ts library. Does anyone kows how to resolve these multiple deinitions?
I think that if I add just the libraries that I use from OpenCV it will be resolved, but I do not know how to do this. I have tried:
target_link_libraries(${Exec8name}_test ${OpenCV}/opencv_core.so* ... )
target_link_libraries(${Exec8name}_test ${OpenCV_LIBS}/opencv_core.so* ... )
target_link_libraries(${Exec8name}_test ${OpenCV_LIBS_DIR}/opencv_core.so* ... )
etc, but I get just errors of not found or No rule to make tarket
I have tried to remove one of the two, but I get errors of
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
...
This is my CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
option(test "Build all tests." OFF)
set(EXECUTABLE_NAME MyProj)
project(${EXECUTABLE_NAME})
set(CMAKE_CXX_FLAGS "-g -Wall")
include_directories( src/main/cpp
${Boost_INCLUDE_DIRS}
)
find_package(OpenCV REQUIRED)
find_package(Boost REQUIRED COMPONENTS filesystem
system
regex
program_options)
add_executable(${EXECUTABLE_NAME}_Sol2
src/main/cpp/main.cpp
src/main/cpp/solution2/MySol2.hpp
src/main/cpp/solution2/MySol2.cpp
)
target_link_libraries(${EXECUTABLE_NAME}_Sol2 ${OpenCV_LIBS}
${Boost_LIBRARIES}
)
if (test)
find_package(GTest REQUIRED)
enable_testing()
include_directories( ${GTEST_INCLUDE_DIRS} )
add_executable(${EXECUTABLE_NAME}_Sol2_test
src/test/cpp/test_Sol2.cpp
src/main/cpp/solution2/MySol2.hpp
src/main/cpp/solution2/MySol2.cpp
)
target_link_libraries(${EXECUTABLE_NAME}_Sol2_test ${OpenCV_LIBRARIES}
${Boost_LIBRARIES}
)
target_link_libraries(${EXECUTABLE_NAME}_Sol2_test ${GTEST_LIBRARIES}
pthread
)
add_test(${EXECUTABLE_NAME}_Sol2_test
${CMAKE_CURRENT_BINARY_DIR}/${EXECUTABLE_NAME}_Sol2_test
)
endif()
Can anyone tell me some ways to fix it?

The "opencv_ts" module contains gtest, so you could just include the required OpenCV modules excluded "ts" module insted of all. For example:
find_package(OpenCV REQUIRED core imgproc highgui)

Add just the libs that I need like
target_link_libraries(${EXECUTABLE_NAME}_Sol2 opencv_core
opencv_highgui
opencv_imgproc
...
)

Related

Undefined reference to GLEW functions when linking GLEW's static binary with CMake

Problem
glew32s.lib is not linking correctly with the main executable. When building with MakeFile given by CMake, an error occurs stating that I have an undefined reference to glewInit().
CMakeFiles\NoGameEngine.dir/objects.a(window.cpp.obj):window.cpp:(.text+0x15d): undefined reference to `glewInit'
However in my top-level CMakeLists.txt I have linked the glew32s.lib through:
target_link_libraries( ${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/Dependencies/glew32s.lib)
I am completely clueless to why I am getting this undefined reference error. Note I have also declared the compile option -DGLEW_STATIC.
What I have tried
Using another way to link the library:
target_link_directories( ${PROJECT_NAME} PRIVATE Dependencies)
target_link_libraries( ${PROJECT_NAME} PRIVATE glew32s.lib)
However I get the following errors:
C:/MinGW64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/PROGRA~4/C__~1/Projects/GAMEPR~1/NOGAME~1/DEPEND~1/glew32s.lib when
searching for -lglew32s
C:/MinGW64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/PROGRA~4/C__~1/Projects/GAMEPR~1/NOGAME~1/DEPEND~1/glew32s.lib when
searching for -lglew32s
C:/MinGW64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/PROGRA~4/C__~1/Projects/GAMEPR~1/NOGAME~1/DEPEND~1\glew32s.lib when
searching for -lglew32s
C:/MinGW64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lglew32s
Resources
CMakeLists.txt:
cmake_minimum_required(VERSION 3.23.)
set(CMAKE_CXX_STANDARD 17)
set(SourceFiles-Core
NoGameEngine-core/src/main.cpp
NoGameEngine-core/src/graphics/window.cpp
)
set(includeFiles-Core NoGameEngine-core/include)
set (includeFiles-Depend Dependencies/include)
add_compile_options(-DGLEW_STATIC)
find_package( OpenGL REQUIRED )
if (OPENGL_FOUND)
MESSAGE("OpenGL Correctly Found")
else (OPENGL_FOUND)
MESSAGE("OpenGL environment missing")
endif()
project(NoGameEngine)
include_directories( ${OPENGL_INCLUDE_DIRS} ${includeFiles-Core} ${includeFiles-Depend})
set( GLFW_BUILD_DOCS OFF CACHE BOOL "GLFW lib only" )
set( GLFW_INSTALL OFF CACHE BOOL "GLFW lib only" )
add_subdirectory( Dependencies/GLFW )
add_executable(${PROJECT_NAME} ${SourceFiles-Core})
target_link_libraries( ${PROJECT_NAME} PRIVATE ${OPENGL_LIBRARIES} glfw)
target_link_libraries( ${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/Dependencies/glew32s.lib)
Directory Hierarchy:
Root:
build
Dependencies
GLFW
include
GL
glew32s.lib
NoGameEngine-core
include
src
CMakeLists.txt

Add ros cmake to an already existing cmake

I have a really big code with this cmake that works:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(MYPROJECT)
set (CMAKE_CXX_STANDARD 11)
find_package(PCL 1.7 REQUIRED)
if(DEFINED PCL_LIBRARIES)
list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4")
endif()
FIND_PACKAGE(Boost COMPONENTS program_options REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (main src/main.cpp)
target_link_libraries (main ${PCL_LIBRARIES})
Now, I want to publish the results of this code to a ros topic. So I added this code to a ros workspace, and need to add ros stuff into the cmake. I changed the project name to the pkg name, and added to the cmake the find_package, include_directories and catkin_package, ending with this CMake:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(plc)
set (CMAKE_CXX_STANDARD 11)
find_package(PCL 1.7 REQUIRED)
if(DEFINED PCL_LIBRARIES)
list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4")
endif()
find_package(catkin REQUIRED COMPONENTS
pcl_conversions
pcl_ros
roscpp
)
FIND_PACKAGE(Boost COMPONENTS program_options REQUIRED)
include_directories(${catkin_INCLUDE_DIRS})
include_directories(${PCL_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
catkin_package(CATKIN_DEPENDS roscpp pcl_ros pcl_conversions)
add_executable (main src/main.cpp)
target_link_libraries (main ${PCL_LIBRARIES})
also added this to the package.xml:
<build_depend>pcl_conversions</build_depend>
<build_depend>pcl_ros</build_depend>
<build_depend>roscpp</build_depend>
<build_export_depend>pcl_conversions</build_export_depend>
<build_export_depend>pcl_ros</build_export_depend>
<build_export_depend>roscpp</build_export_depend>
<exec_depend>pcl_conversions</exec_depend>
<exec_depend>pcl_ros</exec_depend>
<exec_depend>roscpp</exec_depend>
But I keep getting this errors, that according to google means that I made the CMake wrong.
usr/bin/ld: main.cpp:(.text+0x6bdc): undefined reference to `ros::Rate::Rate(double)'
/usr/bin/ld: main.cpp:(.text+0x6beb): undefined reference to `ros::NodeHandle::ok() const'
/usr/bin/ld: main.cpp:(.text+0x6c07): undefined reference to `ros::Time::now()'
/usr/bin/ld: main.cpp:(.text+0x6c3e): undefined reference to `ros::spinOnce()'
/usr/bin/ld: main.cpp:(.text+0x6c4d): undefined reference to `ros::Rate::sleep()'
/usr/bin/ld: main.cpp:(.text+0x6c5e): undefined reference to `ros::Publisher::~Publisher()'
/usr/bin/ld: main.cpp:(.text+0x6c6d): undefined reference to `ros::NodeHandle::~NodeHandle()'
/usr/bin/ld: main.cpp:(.text+0x6cfc): undefined reference to `ros::Publisher::~Publisher()'
/usr/bin/ld: main.cpp:(.text+0x6d0b): undefined reference to `ros::NodeHandle::~NodeHandle()'
Any idea how can I fix this? I'm clueless.
PS: I have another workspace with python ros that publishes/subscribes without problems, and this code was working perfectly before I added the ros part in cpp.
Make sure you also link agains the catkin specified libraries (${catkin_LIBRARIES}), because there the ROS libs are listed in:
target_link_libraries (main
${PCL_LIBRARIES})
${catkin_LIBRARIES}
)

Linker error when compiling with Boost.Filesystem on macOS High Sierra

I'm currently trying to compile a program that uses Boost.Filesystem on macOS High Sierra 10.13.4. I'm also using gcc 7.3 to compile, which I manually installed using Homebrew. The program will compile, but then throws the following error during linking
Undefined symbols for architecture x86_64:
"boost::filesystem::path_traits::dispatch(boost::filesystem::directory_entry const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)", referenced from:
boost::enable_if<boost::filesystem::path_traits::is_pathable<boost::decay<boost::filesystem::directory_entry>::type>, boost::filesystem::path&>::type boost::filesystem::path::operator=<boost::filesystem::directory_entry>(boost::filesystem::directory_entry const&) in world.cc.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
I'm using cmake to build, and my CMakeLists.txt file looks like this
cmake_minimum_required (VERSION 3.0)
MESSAGE(STATUS "Compiler: " ${CMAKE_CXX_COMPILER})
# variables for CMAKE
set(PROJECT sealab)
set(BINARY ${PROJECT}.out)
set(SRC_DIR src/)
set(INC_DIR inc/)
FILE(GLOB_RECURSE SRC ${SRC_DIR}/*.cc)
# library include dirs
set(IMGUI_INC libs/imgui/)
set(SPDLOG_INC libs/spdlog/include/)
set(JSON_INC libs/json/include/)
set(
LIB_INC
${IMGUI_INC}
${SPDLOG_INC}
${JSON_INC}
${GLM_INC}
)
# library src files
FILE(GLOB IMGUI_SRC ${IMGUI_INC}*.cpp)
FILE(GLOB SPDLOG_SRC ${SPDLOG_INC}*.cpp)
set(
LIB_SRC
${IMGUI_SRC}
${SPDLOG_SRC}
)
project(${PROJECT})
# version number
set(${PROJECT}_VERSION_MAJOR 0)
set(${PROJECT}_VERSION_MINOR 1)
# Compilation Database
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-local-typedefs")
# threads
set(THREADS_PREFER_PTHREAD_FLAG ON)
# adding packages
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(glfw3 3.2 REQUIRED)
find_package(Threads REQUIRED)
find_package(Assimp REQUIRED)
find_package(glm REQUIRED)
find_package(Boost COMPONENTS system filesystem REQUIRED)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME ON)
# adding directories and source files
include_directories(
${OPENGL_INCLUDE_DIRS}
${GLEW_INCLUDE_DIRS}
${ASSIMP_INCLUDE_DIRS}
${GLM_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)
include_directories(${INC_DIR} ${LIB_INC})
link_directories(${INC_DIR} ${LIB_INC})
# adding source files
add_executable(${BINARY} ${SRC} ${LIB_SRC})
set_target_properties(${BINARY} PROPERTIES COTIRE_UNITY_TARGET_NAME "unity")
# linking libraries
target_link_libraries(
${BINARY}
OpenGL::GL
${GLEW_LIBRARIES}
Threads::Threads
${ASSIMP_LIBRARIES}
glfw
glm
${Boost_LIBRARIES}
)
I'm using the command cmake -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX . to generate the Makefile, and the environment variables $CC and $CXX are set to the versions of gcc and g++ created by Homebrew.
I've looked at several other stackoverflow answers where people have the same error, and all of those are the result of incorrect linking. I'm linking in the same way that the correct answers say to do, yet the error still persists. Am I still linking it incorrectly or is there something else going on here?
So I found out what was going on. This made me realized that maybe the bottled homebrew Boost 1.66.0 library wasn't built with GCC. I switched the compiler to clang, and now it compiles just fine.

Is there a way to include and link external libraries throughout my project only editing my top level CMakeList?

I'm trying to compile a small project which has both BOOST and PETSc dependencies. I couldn't configure my top level CMakeList in a way to include and link these external libraries to my project. It seems that I can achieve this objective by configuring each CMakeList of each library / executable that I've built, however I'm looking for a more practical way to do so.
Is there any?
As requested, this is my top level CMakeList:
CMAKE_MINIMUM_REQUIRED(VERSION 3.2)
# WHERE THE FILES WILL BE
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/libs)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/shared_libs)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/apps)
# BOOST MANAGEMENT
find_package(Boost)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIR})
endif()
# COMPILER SETTINGS
set(CMAKE_C_COMPILER "mpicc")
set(CMAKE_CXX_COMPILER "mpicxx") # both compilers are in the path
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -pedantic -std=c++11")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -pedantic -std=c++11")
# SET BUILD TYPE
set(CMAKE_BUILD_TYPE "RELEASE")
set(CMAKE_BUILD_DIR "Release")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${CMAKE_BUILD_DIR})
# ABOUT THE PROJECT
project(MinorTest)
set(VERSION_MAJOR "1")
set(VERSION_MINOR "0")
set(VERSION_PATCH "0")
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
# ADD SUBDIRECTORIES
add_subdirectory(MuParserLib)
add_subdirectory(UtilsLib)
#add_subdirectory(UtilsTest)
add_subdirectory(ScriptSystemLib)
add_subdirectory(ScriptSystemTest)
The following errors are shown when linking the executable from ScriptSystemTest project:
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../lib/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
CMakeFiles/ScriptSystemTest.dir/source/TestScriptSystem.cpp.o: In function `init_unit_test_suite(int, char**)':
/home/felipe/Libraries/boost_1_63_0/boost/test/unit_test_suite.hpp:346: undefined reference to `boost::unit_test::framework::master_test_suite()'
CMakeFiles/ScriptSystemTest.dir/source/TestScriptSystem.cpp.o: In function `TestParser::test_method()':
/home/felipe/Workspace/Z_TestEFv/ScriptSystemTest/source/TestScriptSystem.cpp:20: undefined reference to `boost::unit_test::unit_test_log_t::set_checkpoint(boost::unit_test::basic_cstring<char const>, unsigned long, boost::unit_test::basic_cstring<char const>)'
/home/felipe/Workspace/Z_TestEFv/ScriptSystemTest/source/TestScriptSystem.cpp:20: undefined reference to `boost::test_tools::tt_detail::report_assertion(boost::test_tools::assertion_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)'
Finally, this is the ScriptSystemTest CMakeList:
project(ScriptSystemTest)
#
include_directories(${CMAKE_SOURCE_DIR}/${PROJECT_NAME}/include)
include_directories(${CMAKE_SOURCE_DIR}/UtilsLib/include)
include_directories(${CMAKE_SOURCE_DIR}/ScriptSystemLib/include)
include_directories(${CMAKE_SOURCE_DIR}/MuParserLib/include)
#
link_directories(${CMAKE_SOURCE_DIR}/UtilsLib/source)
link_directories(${CMAKE_SOURCE_DIR}/ScriptSystemLib/source)
link_directories(${CMAKE_SOURCE_DIR}/MuParserLib/source)
# SEARCH FOR .CPP FILES
file(GLOB ${PROJECT_NAME}_sources ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}/source/ *.cpp)
#
add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_sources})
#
target_link_libraries(${PROJECT_NAME} UtilsLib)
target_link_libraries(${PROJECT_NAME} ScriptSystemLib)
target_link_libraries(${PROJECT_NAME} MuParserLib)
#
install(
TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION apps
)
Turning my comment into an answer
Extending CMAKE_CXX_STANDARD_LIBRARIES you can do:
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
list(APPEND CMAKE_CXX_STANDARD_LIBRARIES ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY_RELEASE})
endif()
add_subdirectory(ScriptSystemTest)
Or you go the long way of overwriting/extending add_executable() itself:
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
macro(add_executable _target)
_add_executable(${_target} ${ARGN})
target_link_libraries(${_target} Boost::unit_test_framework)
endmacro()
add_subdirectory(ScriptSystemTest)

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)