/home/ubuntu/emvs_ws/src/rpg_emvs/mapper_emvs/src/realtime.cpp:25:62: fatal error: pcl/registration/impl/incremental_registration.hpp: No such file or directory
compilation terminated.
rpg_emvs/mapper_emvs/CMakeFiles/realtime_emvs.dir/build.make:62: recipe for target 'rpg_emvs/mapper_emvs/CMakeFiles/realtime_emvs.dir/src/realtime.cpp.o' failed
make[2]: *** [rpg_emvs/mapper_emvs/CMakeFiles/realtime_emvs.dir/src/realtime.cpp.o] Error 1
I'm getting this error after catkin_make
Theses are the includes in realtime.cpp
#include <pcl/registration/incremental_registration.h>
#include <pcl/registration/icp.h>
CMakeLists.txt file
project(mapper_emvs)
cmake_minimum_required(VERSION 2.8.3)
find_package(catkin_simple REQUIRED)
catkin_simple(ALL_DEPS_REQUIRED)
set(CMAKE_BUILD_TYPE RelWithDebInfo) # Release, RelWithDebInfo
set(CMAKE_CXX_FLAGS "-O3 -fopenmp -std=c++11 ${CMAKE_CXX_FLAGS}")
## Generate dynamic reconfigure parameters in the 'cfg' folder
##generate_dynamic_reconfigure_options(
## cfg/EMVSCfg.cfg
##)
set(HEADERS
include/mapper_emvs/mapper_emvs.hpp
include/mapper_emvs/data_loading.hpp
include/mapper_emvs/depth_vector.hpp
include/mapper_emvs/trajectory.hpp
include/mapper_emvs/geometry_utils.hpp
include/mapper_emvs/median_filtering.hpp
)
set(SOURCES
src/mapper_emvs.cpp
src/data_loading.cpp
src/median_filtering.cpp
)
option(DEFINE_USE_INVERSE_DEPTH "Use linear spacing in inverse depth (if OFF, will use linear spacing in depth)" ON)
if(DEFINE_USE_INVERSE_DEPTH)
add_definitions(-DUSE_INVERSE_DEPTH)
endif(DEFINE_USE_INVERSE_DEPTH)
cs_add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS})
# Executables
################################################################################
cs_add_executable(run_emvs src/main.cpp)
target_link_libraries(run_emvs ${PROJECT_NAME})
cs_add_executable(realtime_emvs src/realtime.cpp)
add_dependencies(realtime_emvs ${PROJECT_NAME}_gencfg)
target_link_libraries(realtime_emvs ${PROJECT_NAME})
################################################################################
cs_install()
cs_export()
Note that I did Catkin_make not catkin build, I don;t know if this makes a difference.
I'm asked to add more details, so please ignore this line :)
You need to add PCL library in your CMakeLists.txt file as follows:
project(mapper_emvs)
cmake_minimum_required(VERSION 2.8.3)
find_package(catkin_simple REQUIRED)
# Adding PCL lib
find_package(PCL REQUIRED)
# Setting include, lib directories and definitions
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS} )
add_definitions(${PCL_DEFINITIONS} )
catkin_simple(ALL_DEPS_REQUIRED)
set(CMAKE_BUILD_TYPE RelWithDebInfo) # Release, RelWithDebInfo
set(CMAKE_CXX_FLAGS "-O3 -fopenmp -std=c++11 ${CMAKE_CXX_FLAGS}")
## Generate dynamic reconfigure parameters in the 'cfg' folder
##generate_dynamic_reconfigure_options(
## cfg/EMVSCfg.cfg
##)
set(HEADERS
include/mapper_emvs/mapper_emvs.hpp
include/mapper_emvs/data_loading.hpp
include/mapper_emvs/depth_vector.hpp
include/mapper_emvs/trajectory.hpp
include/mapper_emvs/geometry_utils.hpp
include/mapper_emvs/median_filtering.hpp
)
set(SOURCES
src/mapper_emvs.cpp
src/data_loading.cpp
src/median_filtering.cpp
)
option(DEFINE_USE_INVERSE_DEPTH "Use linear spacing in inverse depth (if OFF, will use linear spacing in depth)" ON)
if(DEFINE_USE_INVERSE_DEPTH)
add_definitions(-DUSE_INVERSE_DEPTH)
endif(DEFINE_USE_INVERSE_DEPTH)
cs_add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS})
# Executables
################################################################################
cs_add_executable(run_emvs src/main.cpp)
target_link_libraries(run_emvs ${PROJECT_NAME} ${PCL_LIBRARIES})
cs_add_executable(realtime_emvs src/realtime.cpp)
add_dependencies(realtime_emvs ${PROJECT_NAME}_gencfg)
target_link_libraries(realtime_emvs ${PROJECT_NAME} ${PCL_LIBRARIES})
################################################################################
cs_install()
cs_export()
Note: Hope you installed PCL lib. Besides,
I added ${PCL_LIBRARIES} into target_link_libraries. I hope it will work this way, if you are getting some errors, try adding ${PCL_LIBRARIES} into cs_add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${PCL_LIBRARIES}). Please let us know if get errors after applying these changes.
Related
I download OpencV using VCPKG:
./vcpkg install opencv2:x64-windows
Computing installation plan...
The following packages are already installed:
opencv2[core,eigen,jpeg,png,tiff]:x64-windows -> 2.4.13.7#5
Package opencv2:x64-windows is already installed
Total elapsed time: 2.225 ms
The package opencv2:x64-windows provides CMake targets:
find_package(OpenCV CONFIG REQUIRED)
# Note: 15 target(s) were omitted.
target_link_libraries(main PRIVATE opencv_ml opencv_ts opencv_gpu opencv_ocl)
and write cmakelists like this:
cmake_minimum_required(VERSION 3.10)
set(CMAKE_TOOLCHAIN_FILE E:/vcpkg/scripts/buildsystems/vcpkg.cmake
CACHE STRING "Vcpkg toolchain file")
# set the project name
project(QRCODE)
# add the executable
add_executable(qrcode main.cpp)
find_package(OpenCV COMPONENTS REQUIRED)
# Additional Include Directories
include_directories( ${OpenCV_INCLUDE_DIRS} )
# Additional Library Directories
link_directories( ${OpenCV_LIB_DIR} )
# Additional Dependencies
target_link_libraries(qrcode ${OpenCV_LIBS})
message("${OpenCV_DIR}")
message("${OpenCV_INCLUDE_DIRS}")
and what puzzles me is that cmake output looks like this:
E:/vcpkg/installed/x64-windows/share/opencv
/include/opencv;/include
it seems like opencv was not installed successfully, or cmake couldn't find opencv install path.
When I built the project using cmake tool, encountered with fatal error: “opencv2/core/core.hpp”: No such file or directory.
I asked a similar question about linking a project with OpenCV a few days ago. I got that working, but now I've hit a very weird problem using CMake and adding LibTorch to the project.
If I only use OpenCV in the project, everything compiles, links, and runs fine.
But if I add Torch to CMakeLists.txt, I get a linker error:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
set(CMAKE_VERBOSE_MAKEFILE ON)
project(torchscriptie)
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
find_package(Torch HINTS "/usr/local/libtorch")
message(STATUS "TORCH_LIBRARIES = ${TORCH_LIBRARIES}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
add_executable(torchscriptie main.cpp)
target_link_libraries( torchscriptie ${OpenCV_LIBS} )
target_link_libraries(torchscriptie "${TORCH_LIBRARIES}")
set_property(TARGET torchscriptie PROPERTY CXX_STANDARD 14)
This CMakeLists.txt file causes this error:
CMakeFiles/torchscriptie.dir/main.cpp.o: In function `main':
/code/cpp/torchscriptie/main.cpp:18: undefined reference to `cv::imread(std::string const&, int)'
/code/cpp/torchscriptie/main.cpp:24: undefined reference to `cv::namedWindow(std::string const&, int)'
/code/cpp/torchscriptie/main.cpp:25: undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
collect2: error: ld returned 1 exit status
Here's the command:
/usr/bin/c++ -g -rdynamic CMakeFiles/torchscriptie.dir/main.cpp.o -o torchscriptie -Wl,-rpath,/usr/local/lib:/usr/local/libtorch/lib /usr/local/lib/libopencv_gapi.so.4.3.0 /usr/local/lib/libopencv_stitching.so.4.3.0 /usr/local/lib/libopencv_alphamat.so.4.3.0 /usr/local/lib/libopencv_aruco.so.4.3.0 /usr/local/lib/libopencv_bgsegm.so.4.3.0 /usr/local/lib/libopencv_bioinspired.so.4.3.0 /usr/local/lib/libopencv_ccalib.so.4.3.0 /usr/local/lib/libopencv_dnn_objdetect.so.4.3.0 /usr/local/lib/libopencv_dnn_superres.so.4.3.0 /usr/local/lib/libopencv_dpm.so.4.3.0 /usr/local/lib/libopencv_face.so.4.3.0 /usr/local/lib/libopencv_freetype.so.4.3.0 /usr/local/lib/libopencv_fuzzy.so.4.3.0 /usr/local/lib/libopencv_hdf.so.4.3.0 /usr/local/lib/libopencv_hfs.so.4.3.0 /usr/local/lib/libopencv_img_hash.so.4.3.0 /usr/local/lib/libopencv_intensity_transform.so.4.3.0 /usr/local/lib/libopencv_line_descriptor.so.4.3.0 /usr/local/lib/libopencv_quality.so.4.3.0 /usr/local/lib/libopencv_rapid.so.4.3.0 /usr/local/lib/libopencv_reg.so.4.3.0 /usr/local/lib/libopencv_rgbd.so.4.3.0 /usr/local/lib/libopencv_saliency.so.4.3.0 /usr/local/lib/libopencv_stereo.so.4.3.0 /usr/local/lib/libopencv_structured_light.so.4.3.0 /usr/local/lib/libopencv_superres.so.4.3.0 /usr/local/lib/libopencv_surface_matching.so.4.3.0 /usr/local/lib/libopencv_tracking.so.4.3.0 /usr/local/lib/libopencv_videostab.so.4.3.0 /usr/local/lib/libopencv_viz.so.4.3.0 /usr/local/lib/libopencv_xfeatures2d.so.4.3.0 /usr/local/lib/libopencv_xobjdetect.so.4.3.0 /usr/local/lib/libopencv_xphoto.so.4.3.0 /usr/local/libtorch/lib/libtorch.so /usr/local/libtorch/lib/libc10.so /usr/local/lib/libopencv_shape.so.4.3.0 /usr/local/lib/libopencv_highgui.so.4.3.0 /usr/local/lib/libopencv_datasets.so.4.3.0 /usr/local/lib/libopencv_plot.so.4.3.0 /usr/local/lib/libopencv_text.so.4.3.0 /usr/local/lib/libopencv_dnn.so.4.3.0 /usr/local/lib/libopencv_ml.so.4.3.0 /usr/local/lib/libopencv_phase_unwrapping.so.4.3.0 /usr/local/lib/libopencv_optflow.so.4.3.0 /usr/local/lib/libopencv_ximgproc.so.4.3.0 /usr/local/lib/libopencv_video.so.4.3.0 /usr/local/lib/libopencv_videoio.so.4.3.0 /usr/local/lib/libopencv_imgcodecs.so.4.3.0 /usr/local/lib/libopencv_objdetect.so.4.3.0 /usr/local/lib/libopencv_calib3d.so.4.3.0 /usr/local/lib/libopencv_features2d.so.4.3.0 /usr/local/lib/libopencv_flann.so.4.3.0 /usr/local/lib/libopencv_photo.so.4.3.0 /usr/local/lib/libopencv_imgproc.so.4.3.0 /usr/local/lib/libopencv_core.so.4.3.0 -Wl,--no-as-needed,/usr/local/libtorch/lib/libtorch_cpu.so -Wl,--as-needed /usr/local/libtorch/lib/libc10.so -lpthread -Wl,--no-as-needed,/usr/local/libtorch/lib/libtorch.so -Wl,--as-needed
I've tried a lot of different combination of commands, but I cannot figure our what's wrong.
When I echo the TORCH_LIBRARIES variable, it returns:
torch;torch_library;/usr/local/libtorch/lib/libc10.so
If I change the libaries, for example to torch_cpu, I'm able to link OpenCV libraries.
set(TORCH_LIBRARIES torch_cpu)
I have no idea why Torch libraries are causing link errors with OpenCV in the same project.
Any suggestions would be great.
Not sure if this fixes your problem, but I had also a few problems like yours. It is working for me with a cmake file including this:
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(MyProject)
set(CMAKE_CXX_STANDARD 14)
list(APPEND CMAKE_PREFIX_PATH "folderToLibtorch/libtorch/share/cmake")
find_package(Torch REQUIRED)
find_package(OpenCV REQUIRED)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lm -ldl")
add_executable(MyProject ...some project files...)
target_link_libraries(MyProject ${TORCH_LIBRARIES} ${OpenCV_LIBS})
set_property(TARGET MyProject PROPERTY CXX_STANDARD 14)
So make sure list(APPEND CMAKE_PREFIX_PATH "folderToLibtorch/libtorch/share/cmake") is included, this did the trick for me. Also take care to get the right libtorch version from pytorch maybe you should use the lower link and not the "pre-..." version.
Good Luck
The problem is in the version libtorch.
Please use libtorch-cxx11-abi-shared-with-deps not libtorch-shared-with-deps. It is library conflict between libtorch and opencv.
Solution here.
There is my version of CMakeList.txt with CUDA+LIBTORCH+OPENCV support:
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
SET(CUDA_HOME /usr/local/cuda)
SET(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
SET(CUDA_TOOLKIT_ROOT_DIR /usr/local/cuda)
# SET(CUDA_CUBLAS_LIBRARIES /usr/local/cuda/lib64)
SET(CUDA_cublas_device_LIBRARY /usr/local/cuda/lib64)
# SET(CMAKE_CUDA_COMPILER_ENV_VAR /usr/local/cuda/bin/nvcc)
SET(CUDA_INCLUDE_DIRS /usr/local/cuda/include)
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES 50)
endif()
set(OpenCV_DIR /usr/local/lib/cmake/opencv4)
# set(OpenCV_DIR /usr/local/lib)
project(cmake_and_cuda LANGUAGES CXX CUDA)
include(CTest)
find_package(CUDA REQUIRED)
# libtorch with OpenCV support , with fixed BUG !
list(APPEND CMAKE_PREFIX_PATH ./libtorch)
find_package(Torch REQUIRED)
message(STATUS "TORCH_LIBRARIES = ${TORCH_LIBRARIES}")
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV_LIBS = ${OpenCV_LIBS}")
# ADD OWN CUDA FILES FOR BUILD LIBRARY.
add_library(particles_new_lib STATIC
torch_module_plus_cuda.cu
torch_module_plus_cuda.h
)
target_compile_features(particles_new_lib PUBLIC cxx_std_14)
# We need to explicitly state that we need all CUDA files in the
# particles_new_lib library to be built with -dc as the member functions
# could be called by other libraries and executables
set_target_properties( particles_new_lib
PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
add_executable(particle_cuda_test torch_and_cuda_call.cpp)
set_property(TARGET particle_cuda_test
PROPERTY CUDA_SEPARABLE_COMPILATION ON)
# LINK ALL LIBRARIES TO TARGET particle_cuda_test
target_link_libraries(particle_cuda_test PRIVATE ${TORCH_LIBRARIES} ${OpenCV_LIBS} particles_new_lib)
# LINK LIBRARIES
target_link_libraries(particle_cuda_test PRIVATE particles_new_lib)
set_property(TARGET particle_cuda_test PROPERTY CXX_STANDARD 14)
I'm getting this error when I catkin_make my workspace:
[100%] Linking CXX executable /home/ankilp/test_ws/devel/lib/lidar_depth/lidar_depth
/usr/bin/ld: cannot find -lQt5::Widgets
This is my CMakeList file:
cmake_minimum_required(VERSION 2.8.3)
project(lidar_depth)
## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
genmsg
)
find_package( PCL REQUIRED)
find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED)
include(${QT_USE_FILE})
add_definitions(-DQT_NO_KEYWORDS)
catkin_package(
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
# include
${catkin_INCLUDE_DIRS}
${PCL_INCLUDE_DIRS}
)
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(${PROJECT_NAME} src/LidarDepth.cpp src/Projection_matrices.hpp)
target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
${PCL_LIBRARIES}
${QT_LIBRARIES}
)
I don't explicitly use anything related to Qt. I installed Qt5 separately but the problem persists. Is there a separate process to link Qt to my system?
It looks like you're using at least ROS Kinetic (based on the comment where you add compile options). Most things in Kinetic depend on Qt5 instead of Qt4. Try making the following changes to your CMakeLists.txt file:
Replace this line
find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED)
with these lines
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
set(QT_LIBRARIES Qt5::Widgets)
If this doesn't work for you, leave a comment as I have a working CMakeLists.txt file for Qt5 in Kinetic and can probably determine what else needs changed, but I think that is the minimal change to make.
If you have installed Qt seperately, you have to tell CMAKE where it can find you installation. This can be done by specifying the CMAKE_PREFIX_PATH inside the CMakeLists.txt file or in the terminal before executing cmake (ref). E.g.:
$ export CMAKE_PREFIX_PATH=/location/to/you/installation
I'm trying to compile a ROS project involving catkin_make. The project involves - amongst others- a tool to convert opencv matrices to ros matrices called cv_bridge. However, when trying to compile my catkin_ws I'm getting the following error:
CMake Error at cv_bridge/test/CMakeLists.txt:7 (target_link_libraries):
Cannot specify link libraries for target "cv_bridge-utest" which is not
built by this project.
Does anyone know this error? I'm quite new to ROS, so I'm not sure how to tell ROS to compile the entire catkin_ws/src directory. In that latter folder all necessary folders should be present. There is also catkin_ws/src/cv_bridge but maybe it tries to compile the folder in the wrong order ...
I don't know what you have written in your CMakeLists. Supposing that the error lays there, you can use a CMakeLists.txt like this:
cmake_minimum_required(VERSION 2.8.3)
project(your_project)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
cv_bridge
)
find_package(OpenCV REQUIRED)
###########
## Build ##
###########
catkin_package()
include_directories(
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
include
)
add_executable(executable src/your_file.cpp)
target_link_libraries(executable ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
In your package.xml add these lines:
<build_depend>opencv2</build_depend>
<build_depend>cv_bridge</build_depend>
<run_depend>opencv2</run_depend>
<run_depend>cv_bridge</run_depend>
To compile the folder you just have to go to your catkin directory and type: catkin_make
If you have built your workspace in the right way, it should compile without error.
I have OpenCV 3.0.0 installed in /usr/local/opencv-3.0.0
I am trying to construct a CMakeLists file to build a library against this OpenCV 3.0.0. The CMakeLists.txt is as follows:
cmake_minimum_required(VERSION 2.8)
project(STT_People_Tracker)
cmake_policy(SET CMP0016 NEW)
# compilation mode setup
#set(CMAKE_BUILD_TYPE Release)
set(CMAKE_BUILD_TYPE Debug)
# set OpenCV directories - CHANGE DEPENDING ON SYSTEM
set(OpenCV_PATH "/usr/local/opencv-3.0.0")
set(OpenCV_INCLUDE_DIRS "${OpenCV_PATH}/include")
set(OpenCV_LIBS "${OpenCV_PATH}/lib/")
# set environment variables
set(SOURCES_PATH "${CMAKE_SOURCE_DIR}/Sources")
set(INCLUDES_PATH "${SOURCES_PATH}/include")
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(OUTPUT_PATH "../Debug")
message(STATUS "Compiling in DEBUG mode")
elseif(CMAKE_BUILD_TYPE MATCHES Release)
set(OUTPUT_PATH "../Release")
message(STATUS "Compiling in RELEASE mode")
endif()
include_directories(${INCLUDES_PATH})
include_directories(${OpenCV_INCLUDE_DIRS})
# compilation of executables
message(STATUS "configuring executables...")
add_executable(${OUTPUT_PATH}/mainTest ${SOURCES_PATH}/mainTest.cpp)
# compilation of libraries
message(STATUS "configuring libraries...")
add_library(${OUTPUT_PATH}/background_substractor ${SOURCES_PATH}/background_substractor.cpp)
# set linker options
link_directories(${OpenCV_LIBS})
target_link_libraries(${OUTPUT_PATH}/mainTest opencv_core opencv_highgui)
target_link_libraries(${OUTPUT_PATH}/background_substractor opencv_core opencv_highgui)
message(STATUS "cmake configuration complete")
It is a fairly simple Cmake file, however, I have the following problems/doubts:
1.-How can I know I am using OpenCV 3, and not other versions of OpenCV present in the system?
2.- When compiling the file background_substractor, its associated header file can not be located, although I have checked the path and it is correctly assigned in the set(INCLUDES_PATH "${SOURCES_PATH}/include"):
/home/alberto/STT_People_Tracking/Sources/background_substractor.cpp:3:36: fatal error: background_substractor.h: No such file or directory
#include "background_substractor.h"
^
compilation terminated.
make[2]: *** [CMakeFiles/../Debug/background_substractor.dir/Sources/background_substractor.cpp.o] Error 1
make[1]: *** [CMakeFiles/../Debug/background_substractor.dir/all] Error 2
make: *** [all] Error 2
3.- Finally, and if I comment the header file, I have problems linking:
Linking CXX static library lib../Debug/background_substractor.a
/usr/bin/ar: lib../Debug/background_substractor.a: No such file or directory
make[2]: *** [lib../Debug/background_substractor.a] Error 1
make[1]: *** [CMakeFiles/../Debug/background_substractor.dir/all] Error 2
make: *** [all] Error 2
I have tried everything: Specifying the include files in the add_executable() and add_library() commands, I have checked paths and they are ok, etc etc.
Could anyone more experienced with CMake, give me a little hand?
Thank you very much in advance,
Alberto
How can I know I am using OpenCV 3, and not other versions of OpenCV present in the system?
Your project should check that.
But usually projects just use find_package command for fill variables related to 3d-party library. This command perform all needed checks. In your case it could be
find_package(OpenCV 3 REQUIRED)
call, which fills OpenCV_LIBS and OpenCV_INCLUDE_DIRS variables automatically. This command, by default, search OpenCV installation in default paths, but you can adjust searching algorithm by using parameters to cmake (so, you needn't to change CMakeLists.txt when you build the project on other machine). E.g., this way
cmake -DOpenCV_DIR=/usr/local/opencv-3.0.0 <source-dir>
you can specify precise installation path of OpenCV.
When compiling the file background_substractor, its associated header file can not be located...
Cannot suggest anything aside from checking file existence
/home/alberto/STT_People_Tracking/Sources/include/background_substractor.h
But this also can be a result of the 3d issue(see below).
Finally, and if I comment the header file, I have problems linking...
Your usage of CMake targets is incorrect. Unlike to make targets, which usually are files, CMake targets are simple names. By default, name of library/executable target determines filename of the library/executable file, produced by this target, but this can be changed. Directory, where resulted file will be located, can be adjusted using CMAKE_<TYPE>_OUTPUT_DIRECTORY variables, where <TYPE> can be ARCHIVE, LIBRARY or RUNTIME depending on target type.
Correct CMake script would be:
cmake_minimum_required(VERSION 2.8)
project(STT_People_Tracker)
cmake_policy(SET CMP0016 NEW)
# compilation mode setup
#set(CMAKE_BUILD_TYPE Release)
set(CMAKE_BUILD_TYPE Debug)
# set OpenCV directories using find_package.
find_package(OpenCV 3 REQUIRED)
# set environment variables
set(SOURCES_PATH "${CMAKE_SOURCE_DIR}/Sources")
set(INCLUDES_PATH "${SOURCES_PATH}/include")
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(OUTPUT_PATH "${CMAKE_BINARY_DIR}/Debug") # Use absolute path
message(STATUS "Compiling in DEBUG mode")
elseif(CMAKE_BUILD_TYPE MATCHES Release)
set(OUTPUT_PATH "${CMAKE_BINARY_DIR}/Release")
message(STATUS "Compiling in RELEASE mode")
endif()
# Set output directory for STATIC libraries and executables
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_PATH})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_PATH})
include_directories(${INCLUDES_PATH})
include_directories(${OpenCV_INCLUDE_DIRS})
# compilation of executables
message(STATUS "configuring executables...")
add_executable(mainTest ${SOURCES_PATH}/mainTest.cpp) # Use simple name as a target
# compilation of libraries
message(STATUS "configuring libraries...")
add_library(background_substractor ${SOURCES_PATH}/background_substractor.cpp) # Use simple name as a target
# set linker options
# Command below is no-op: OpenCV libraries enumerated using absolute paths
# link_directories(${OpenCV_LINK_DIRECTORIES})
target_link_libraries(mainTest ${OpenCV_LIBS}) # Variable OpenCV_LIBS contains OpenCV libraries needed to link with
target_link_libraries(background_substractor ${OpenCV_LIBS})
message(STATUS "cmake configuration complete")