Cmake and Qt5 linking error - c++

I'm trying to build a Qt5 project with Cmake in order to add some new librairies. The cmake goes well but I have a linking issue when building :
Linking CXX executable bin/qGo
CMakeFiles/qGo.dir/src/main.cpp.o: dans la fonction « main »:
main.cpp:(.text+0x102b): undefined reference to « qInitResources_application() »
collect2: error: ld returned 1 exit status
make[2]: *** [bin/qGo] Erreur 1
make[1]: *** [CMakeFiles/qGo.dir/all] Erreur 2
make: *** [all] Erreur 2
Here is my CMakeLists.txt :
cmake_minimum_required(VERSION 2.8.11)
project (qGo)
SET(CMAKE_MODULE_PATH /usr/local/lib/cmake/)
# Répertoire d'installation de Qt5 (dépend de l'installation)
SET(CMAKE_PREFIX_PATH "~/Qt/5.4/gcc/")
find_package (OpenCV REQUIRED)
find_package (aruco REQUIRED)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Use moc files in the bin folder
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
# Find the Qt5 components
find_package(Qt5Core)
find_package(Qt5Widgets)
find_package(Qt5Network)
find_package(Qt5Multimedia)
set(EXECUTABLE_OUTPUT_PATH bin)
SET(CMAKE_CXX_FLAGS "-std=c++11")
include_directories(src)
include_directories(src/audio)
include_directories(src/board)
include_directories(src/game_interfaces)
include_directories(src/game_tree)
include_directories(src/gtp)
include_directories(src/network)
include_directories(src/resources)
include_directories(src/sgf)
include_directories(src/translations)
file(
GLOB_RECURSE
source_files
src/*
)
file(
GLOB_RECURSE
ui_files
src/*.ui
)
file(
GLOB_RECURSE
header_files
src/*.h
src/*.hpp
)
QT5_WRAP_UI(header_ui ${ui_files})
# Tell CMake to create the helloworld executable
add_executable(qGo ${source_files} ${header_ui})
# Use the Widgets module from Qt 5.
target_link_libraries(qGo Qt5::Core Qt5::Widgets Qt5::Network Qt5::Multimedia ${OpenCV_LIBS} ${aruco_LIBS})
I have also tried to add libraries with ${Qt5Widgets_INCLUDES} or ${Qt5Widgets_DEFINITIONS} but it did the same.
I've also tried to compile with QtCreator and it works so the problem is with cmake.

I think you forget to append moc and resources to your executable use qt5_wrap_cpp() for mocs use qt5_add_resources() for resources.
Then you must append vars to add_executable check out this link.

Related

Duplicate symbol QT5 mac m1

I'm trying to compile QT5 in C++ with Cmake on mac M1,
For now i can try with Fedora and it's working, but not on my mac.
This is my CMake File :
cmake_minimum_required(VERSION 3.0)
project(rtype)
set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CPACK_OUTPUT_FILE_PREFIX "pack")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/bin)
add_executable(${PROJECT_NAME} src/ecs/main.cpp)
# Adding QT5 dependencies
find_package(Qt5 COMPONENTS Core Network REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network)
# Adding SFML dependencies
find_package(SFML COMPONENTS system window graphics CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE sfml-system sfml-window sfml-graphics)
# Ajouter les includes pour SFML
target_include_directories(${PROJECT_NAME}
PRIVATE
${SFML_INCLUDE_DIRS})
# Setting up the CPack generator
set(CPACK_GENERATOR ZIP) # for macOS and Linux
set(CPACK_BUNDLE_NAME ${PROJECT_NAME})
set(CPACK_BUNDLE_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist)
set(CPACK_BUNDLE_ICON ${CMAKE_CURRENT_SOURCE_DIR}/icon.icns)
set(CPACK_GENERATOR NSIS) # for Windows
set(CPACK_PACKAGE_NAME "RType")
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
include(CPack)
# Setting up the install targets
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin)
install(FILES README.md
DESTINATION .)
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/build.sh
DESTINATION .)
If I transform this :
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network)
to this :
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core)
or this :
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Network)
It's working perfectly, but with both its make this error :
[ 20%] Automatic MOC for target rtype
[ 20%] Built target rtype_autogen
[ 40%] Linking CXX executable /Users/ilaan/Documents/Epitech/Tek3/R-Type/client/bin/rtype
duplicate symbol 'qt_apple_sharedApplication()' in:
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib/libQt5Core.a(qcore_mac.o)
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib//libQt5Core.a(qcore_mac.o)
duplicate symbol 'qt_apple_check_os_version()' in:
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib/libQt5Core.a(qcore_mac.o)
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib//libQt5Core.a(qcore_mac.o)
duplicate symbol 'qt_apple_isApplicationExtension()' in:
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib/libQt5Core.a(qcore_mac.o)
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib//libQt5Core.a(qcore_mac.o)
[...]
duplicate symbol 'RunLoopDebugger::staticMetaObject' in:
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib/libQt5Core.a(qeventdispatcher_cf.o)
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib//libQt5Core.a(qeventdispatcher_cf.o)
duplicate symbol 'QEventDispatcherCoreFoundation::staticMetaObject' in:
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib/libQt5Core.a(qeventdispatcher_cf.o)
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib//libQt5Core.a(qeventdispatcher_cf.o)
duplicate symbol 'QEventDispatcherCoreFoundation::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)' in:
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib/libQt5Core.a(qeventdispatcher_cf.o)
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib//libQt5Core.a(qeventdispatcher_cf.o)
ld: 94 duplicate symbols for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [/Users/ilaan/Documents/Epitech/Tek3/R-Type/client/bin/rtype] Error 1
make[1]: *** [CMakeFiles/rtype.dir/all] Error 2
make: *** [all] Error 2
I don't understand why, is not compatible with M1 Chipset ?
Thank you,
Ilan

How to create CMakeList.txt for Onboard-SDK project on Debian 10

I would like to compile my own project. I have error with **make**. cmake .. works properly.
I tried to compile the example in /Onboard-SDK/sample/platform/telemetry.
I did mkdir build and cd build in telemetry directory.
This is my CMakeList.txt
cmake_minimum_required(VERSION 2.8)
project(djiosdk-telemetry-sample)
# Compiler flags: link with pthread and enable C++11 support
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -g -O0")
# Tell the project where osdk-core is located
if(NOT ONBOARDSDK_SOURCE)
set(ONBOARDSDK_SOURCE "/home/pi/Onboard-SDK/osdk-core")
#set(ONBOARDSDK_SOURCE "/usr/local/include")
endif()
# Specify locations for osdk-core headers
include_directories(${ONBOARDSDK_SOURCE}/api/inc)
include_directories(${ONBOARDSDK_SOURCE}/utility/inc)
include_directories(${ONBOARDSDK_SOURCE}/hal/inc)
include_directories(${ONBOARDSDK_SOURCE}/protocol/inc)
include_directories(${ONBOARDSDK_SOURCE}/platform/linux/inc)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../hal)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../osal)
include_directories(include /usr/local/include)
include_directories(${ONBOARDSDK_SOURCE}/../sample/core/inc)
# User-code related project files
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common)
FILE(GLOB SOURCE_FILES *.hpp *.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../common/dji_linux_environment.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../common/dji_linux_helpers.cpp
main.cpp
telemetry_sample.cpp
)
if (OSDK_HOTPLUG)
FILE(GLOB SOURCE_FILES ${SOURCE_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/../hal/hotplug/*.c)
endif ()
# Target and linking
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} djiosdk-core)
This is the result after make
[ 20%] Linking CXX executable djiosdk-telemetry-sample
/usr/bin/ld: //usr/local/lib/libdjiosdk-core.a(dji_legacy_linker.cpp.o): in function `DJI::OSDK::LegacyLinker::legacyX5SEnableTask(void*)':
/home/pi/Onboard-SDK/osdk-core/api/src/dji_legacy_linker.cpp:69: **undefined reference to `DJI::OSDK**::Linker::getLocalSenderId()'
/usr/bin/ld: /home/pi/Onboard-SDK/osdk-core/api/src/dji_legacy_linker.cpp:71: **undefined reference** to `OsdkOsal_TaskSleepMs'
/usr/bin/ld: /home/pi/Onboard-SDK/osdk-core/api/src/dji_legacy_linker.cpp:72: **undefined reference** to `**DJI::OSDK**::Linker::isUSBPlugged()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/djiosdk-telemetry-sample.dir/build.make:129: djiosdk-telemetry-sample] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/djiosdk-telemetry-sample.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I often have [100%] Linking CXX executable djiosdk-telemetry-sample.
The main problem is with "undefined reference".
I create CMakeList.txt according to: https://developer.dji.com/onboard-sdk/documentation/development-workflow/integrate-sdk.html
What I should do?
The proper CMakeList.txt for creating your own project (example based on telemetry sample):
cmake_minimum_required(VERSION 2.8)
project(djiosdk-telemetry-sample)
set(ARCH armv7)
# Compiler flags: link with pthread and enable C++11 support
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -g -O0")
# Tell the project where osdk-core is located
if(NOT ONBOARDSDK_SOURCE)
set(ONBOARDSDK_SOURCE "/home/pi/Onboard-SDK/osdk-core")
endif()
set(CURRENT_CMAKE_MODULE_PATH ${ONBOARDSDK_SOURCE}/cmake-modules)
# Specify locations for osdk-core headers
include_directories(${ONBOARDSDK_SOURCE}/api/inc)
include_directories(${ONBOARDSDK_SOURCE}/utility/inc)
include_directories(${ONBOARDSDK_SOURCE}/hal/inc)
include_directories(${ONBOARDSDK_SOURCE}/protocol/inc)
include_directories(${ONBOARDSDK_SOURCE}/platform/linux/inc)
include_directories(${ONBOARDSDK_SOURCE}/linker/${ARCH}/inc)
include_directories(${ONBOARDSDK_SOURCE}/../sample/platform/linux/hal)
include_directories(${ONBOARDSDK_SOURCE}/../sample/platform/linux/hal/hotplug)
include_directories(${ONBOARDSDK_SOURCE}/../sample/platform/linux/osal)
include_directories(include /usr/local/include)
include_directories(include /usr/local/lib)
include_directories(${ONBOARDSDK_SOURCE}/../sample/core/inc)
# User-code related project files
include_directories(${ONBOARDSDK_SOURCE}/../sample/platform/linux/common)
FILE(GLOB SOURCE_FILES *.hpp *.cpp
${ONBOARDSDK_SOURCE}/../sample/platform/linux/common/dji_linux_environment.cpp
${ONBOARDSDK_SOURCE}/../sample/platform/linux/common/dji_linux_helpers.cpp
${ONBOARDSDK_SOURCE}/../sample/platform/linux/hal/osdkhal_linux.c
${ONBOARDSDK_SOURCE}/../sample/platform/linux/osal/osdkosal_linux.c
)
if (OSDK_HOTPLUG)
FILE(GLOB SOURCE_FILES ${SOURCE_FILES} ${ONBOARDSDK_SOURCE}/../sample/platform/linux/hal/hotplug/*.c)
endif ()
link_libraries(dji-linker)
link_directories(/usr/local/include /usr/local/lib)
link_libraries(${ONBOARDSDK_SOURCE}/linker/${ARCH}/lib/libdji-linker.a)
set(CMAKE_MODULE_PATH ${CURRENT_CMAKE_MODULE_PATH})
find_package(LibUSB REQUIRED)
find_package(FFMPEG REQUIRED)
include_directories(${ADVANCED_SENSING_HEADERS_DIR})
# Target and linking
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} PUBLIC djiosdk-core)
target_link_libraries(${PROJECT_NAME} PUBLIC dji-linker)
target_link_libraries(${PROJECT_NAME} PUBLIC ${ONBOARDSDK_SOURCE}/linker/${ARCH}/lib/libdji-linker.a)
target_include_directories(${PROJECT_NAME} PUBLIC ${LIBUSB_1_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIBUSB_1_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PUBLIC ${FFMPEG_LIBRARIES})
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${ADVANCED_SENSING_HEADERS_DIR}>)
target_link_libraries(${PROJECT_NAME} PRIVATE advanced-sensing)
target_include_directories(${PROJECT_NAME} PUBLIC ${FFMPEG_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} PUBLIC ${FFMPEG_LIBRARIES})

C++ ZBar cmake error 'File not found' when including

I have a problem when I include ZBar in my C++ script. I already tried adding it via a CMakelists.txt:
cmake_minimum_required(VERSION 2.8.12)
project( Barcode-cpp )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} ${ZBARCV_SOURCE_DIR} )
set(CMAKE_MODULE_PATH ${ZBARCV_SOURCE_DIRS})
add_compile_options(-std=c++11)
add_library( src
src/VideoVeed.h
src/VideoVeed.cpp
src/Crop.h
src/Crop.cpp
src/Barcodes.h
src/Barcodes.cpp
)
add_executable( program
program/main.cpp
)
target_link_libraries( program src ${OpenCV_LIBS} ${ZBAR_LIBRARIES} zbar )
I'm on mac. I looked and my zbar.h file is located in /usr/local/include/ where it's supposed to be.
I include it like this: #include <zbar.h>
I hope someone is able to help me. Thanks in advance!
EDIT:
Full make error log:
/Users/mathijs/Documents/Barcode-cpp/src/Barcodes.h:7:10: fatal error: 'zbar.h' file not found
#include <zbar.h>
^~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/src.dir/src/VideoVeed.cpp.o] Error 1
make[1]: *** [CMakeFiles/src.dir/all] Error 2
make: *** [all] Error 2
I just checked; the Brew package for ZBar includes a packageconfig file (zbar.pc)
That means you can use modern CMake tooling instead of cargo culting:
cmake_minimum_required(VERSION 3.8)
project( Barcode-cpp )
find_package( OpenCV REQUIRED )
include_directories(${OpenCV_INCLUDE_DIRS})
set(CMAKE_CXX_STANDARD 11)
add_library( src
src/VideoVeed.h
src/VideoVeed.cpp
src/Crop.h
src/Crop.cpp
src/Barcodes.h
src/Barcodes.cpp
)
add_executable( program
program/main.cpp
)
target_link_libraries(program src ${OpenCV_LIBS})
find_package(PkgConfig REQUIRED)
pkg_check_modules(ZBar REQUIRED IMPORTED_TARGET zbar)
target_link_libraries(program PkgConfig::ZBar)
The pkg_check_modules will read the zbar.pc file and generate an IMPORTED target named PkgConfig::ZBar that will automatically set both include paths and linker paths for program.

Migration from qmake to cmake

I have followed this guide http://doc.qt.io/qt-5/gettingstartedqt.html and everything works fine.
But now I want to convert this project from qmake to cmake; this is the CMakeLists.txt
project(Notepad)
# Application Version, managed by release script
set(APPLICATIONS_VERSION_MAJOR "0")
set(APPLICATIONS_VERSION_MINOR "0")
set(APPLICATIONS_VERSION_MICRO "1")
set(APPLICATIONS_VERSION "${APPLICATIONS_VERSION_MAJOR}.${APPLICATIONS_VERSION_MINOR}.${APPLICATIONS_VERSION_MICRO}")
# Minimum required software
set(CMAKE_MIN_REQUIRED_VERSION "3.7.2")
set(QT_MIN_REQUIRED_VERSION "5.7.1")
set(KF5_MIN_REQUIRED_VERSION "5.31.0")
set(ECM_MIN_REQUIRED_VERSION "5.31.0")
cmake_minimum_required(VERSION "${CMAKE_MIN_REQUIRED_VERSION}" FATAL_ERROR)
# Configure ECM
find_package(ECM "${ECM_MIN_REQUIRED_VERSION}" REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
include(FeatureSummary)
include(ECMSetupVersion)
# Generate header with version number
ecm_setup_version("${APPLICATIONS_VERSION}" VARIABLE_PREFIX NOTEPAD
VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/notepad_version.h"
)
# Find Qt modules
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
Core
Gui
Widgets
)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_CXX_STANDARD 11) # C++11...
set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11
set(notepad_SRCS main.cpp notepad.h notepad.cpp)
add_executable(notepad ${notepad_SRCS})
target_link_libraries(notepad
Qt5::Widgets
Qt5::Core
Qt5::Gui
)
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
And I get this output:
/documenti/deglans/Programmazione/QtCreator/Notepad/build> make -j4
Scanning dependencies of target notepad_automoc
[ 25%] Automatic uic for target notepad
Generating ui header ui_notepad.h
[ 25%] Built target notepad_automoc
Scanning dependencies of target notepad
[ 50%] Building CXX object CMakeFiles/notepad.dir/main.cpp.o
[ 75%] Building CXX object CMakeFiles/notepad.dir/notepad.cpp.o
[100%] Linking CXX executable notepad
CMakeFiles/notepad.dir/notepad.cpp.o: In function `Notepad::Notepad(QWidget*)':
/documenti/deglans/Programmazione/QtCreator/Notepad/notepad.cpp:28: undefined reference to `vtable for Notepad'
/documenti/deglans/Programmazione/QtCreator/Notepad/notepad.cpp:28: undefined reference to `vtable for Notepad'
CMakeFiles/notepad.dir/notepad.cpp.o: In function `Notepad::~Notepad()':
/documenti/deglans/Programmazione/QtCreator/Notepad/notepad.cpp:33: undefined reference to `vtable for Notepad'
/documenti/deglans/Programmazione/QtCreator/Notepad/notepad.cpp:33: undefined reference to `vtable for Notepad'
CMakeFiles/notepad.dir/notepad.cpp.o: In function `Notepad::tr(char const*, char const*, int)':
/documenti/deglans/Programmazione/QtCreator/Notepad/notepad.h:28: undefined reference to `Notepad::staticMetaObject'
collect2: error: ld returned 1 exit status
CMakeFiles/notepad.dir/build.make:123: recipe for target 'notepad' failed
make[2]: *** [notepad] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/notepad.dir/all' failed
make[1]: *** [CMakeFiles/notepad.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
*** Errore: Codice di uscita 2 ***
This is the part of code that give error when using cmake:
Notepad::Notepad(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Notepad)
{
ui->setupUi(this);
}
Notepad::~Notepad()
{
delete ui;
}
Note that with qmake and QtCreator I have non problem, the problem born when I try to use KDevelop and cmake.
I have resolved the problem by adding this line set(CMAKE_AUTOMOC ON) as suggested by Lorenz.
So CMakeLists.txt become:
project(Notepad)
# Application Version, managed by release script
set(APPLICATIONS_VERSION_MAJOR "0")
set(APPLICATIONS_VERSION_MINOR "0")
set(APPLICATIONS_VERSION_MICRO "1")
set(APPLICATIONS_VERSION "${APPLICATIONS_VERSION_MAJOR}.${APPLICATIONS_VERSION_MINOR}.${APPLICATIONS_VERSION_MICRO}")
# Minimum required software
set(CMAKE_MIN_REQUIRED_VERSION "3.7.2")
set(QT_MIN_REQUIRED_VERSION "5.7.1")
set(KF5_MIN_REQUIRED_VERSION "5.31.0")
set(ECM_MIN_REQUIRED_VERSION "5.31.0")
cmake_minimum_required(VERSION "${CMAKE_MIN_REQUIRED_VERSION}" FATAL_ERROR)
# Configure ECM
find_package(ECM "${ECM_MIN_REQUIRED_VERSION}" REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
include(FeatureSummary)
include(ECMSetupVersion)
# Generate header with version number
ecm_setup_version("${APPLICATIONS_VERSION}" VARIABLE_PREFIX NOTEPAD
VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/notepad_version.h"
)
# Find Qt modules
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
Core
Gui
Widgets
)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON) # <<<<<<<-----------------------------
set(CMAKE_CXX_STANDARD 11) # C++11...
set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11
set(notepad_SRCS main.cpp notepad.h notepad.cpp)
add_executable(notepad ${notepad_SRCS})
target_link_libraries(notepad
Qt5::Widgets
Qt5::Core
Qt5::Gui
)
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)

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)