CMake does not set variables for g2o - c++

On macOS 11.0, I downloaded and built g2o (https://github.com/RainerKuemmerle/g2o) and installed it using cmake --install .
I then tried to include it in my own project via CMake like this (CMakeLists.txt):
cmake_minimum_required (VERSION 3.14)
project (MY-PROJECT)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# PkgConfig to find other packages easily
find_package(PkgConfig REQUIRED)
# find required modules
pkg_check_modules(OpenCV REQUIRED opencv4)
find_package(Eigen3 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(G2O REQUIRED)
message(STATUS "G2O FOUND: ")
message(STATUS ${G2O_FOUND}) # prints 1
message(STATUS "G2O INCLUDE DIRS: ")
message(STATUS ${G2O_INCLUDE_DIRS}) # prints nothing
message(STATUS "G2O Link Libraries: ")
message(STATUS ${G2O_LINK_LIBRARIES}) # prints nothing
message(STATUS "EIGEN3 INCLUDE DIRS: ")
message(STATUS ${EIGEN3_INCLUDE_DIRS}) # prints /usr/local/include/eigen3
CMake sets G2O_FOUND to 1, indicating that it successfully found g2o. However, the other two variables are not set, so the include- and library-files are not found. I solved this by adding
set(G2O_INCLUDE_DIRS
/usr/local/include)
set(G2O_LIBS
/usr/local/lib/libg2o_core.dylib
/usr/local/lib/libg2o_types_slam3d.dylib
#...
)
include_directories(
G2O_INCLUDE_DIRS
)
target_link_libraries(
MY-PROJECT
${G2O_LIBS}
)
to CMakeLists.txt, but I am still curious why CMake did find g2o but not set the variables accordingly.

why CMake did find g2o but not set the variables accordingly.
FindG2O.cmake does not set these variables, so they are not set. The variables checked for G2O_FOUND to be set are G2O_STUFF_LIBRARY AND G2O_CORE_LIBRARY AND G2O_INCLUDE_DIR AND G2O_SOLVERS_FOUND.
There is no rule that find_package has to set _LIBRARIES or _INCLUDE_DIRS variables - every package is a little different, consult that particular package. If writing FindXXX file, use interface or imported libraries instead of variables.

Related

CMake: Could not find Boost (missing: serialization)

I am cursed with the willingness to create an application for all OS.
Unfortunately, this includes using Windows.
cmake_minimum_required(VERSION 3.17)
project(Odin)
include_directories(Odin/engine)
include_directories(Odin/uci)
include_directories(Odin/util)
# add our cmake modules under cmake/
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
#AddBOOST
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
find_package(Boost 1.74.0 REQUIRED serialization)
#ENDBOOST
message(STATUS "---------------------")
message(STATUS "Boost_FOUND: ${Boost_FOUND}")
message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
message(STATUS "---------------------")
# Include CPM dependency manager
include(CPM)
# enable testing
enable_testing()
# Pull doctest using CPM
cpmaddpackage("gh:onqtam/doctest#2.4.5")
# add the CMake modules for automatic test discovery so we can use
# doctest_discover_tests() CMake
set(CMAKE_MODULE_PATH "${doctest_SOURCE_DIR}/scripts/cmake"
${CMAKE_MODULE_PATH})
add_executable(Odin
Odin/engine/Odin.cc
Odin/main.cc
Odin/engine/Board.cc
Odin/engine/Figure.cc
Odin/util/Utility.cc
Odin/engine/Node.cc
Odin/engine/Link.cc
Odin/engine/Odin.h
Odin/engine/Board.h
Odin/engine/Figure.h
Odin/util/Utility.h
Odin/engine/Node.h
Odin/engine/Link.h
)
target_link_libraries(Odin PRIVATE Boost::serialization)
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native")
this cmake does not work on Windows:
The error reads:
Could NOT find Boost (missing serialization) (found 1.74.0, minimum required is "1.74.0")
If I look into the folder, there is a serialization folder. I also tried different boost versions and different IDEs (VS 2019 + CLION).
I hope someone can help me.

Encounter issue with `find_package` command in Visual Studio CMake

I'm operating under a new learning curve here with c++ and using CMake in Visual Studio. Here is the partial code up until the point where I receive the error:
project(libfranka
VERSION 0.8.0
LANGUAGES CXX
)
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(MSVC)
add_compile_options(/W0)
else()
add_compile_options(-Wall -Wextra)
endif()
set(THIRDPARTY_SOURCES_DIR "${CMAKE_SOURCE_DIR}/3rdparty" CACHE PATH
"Directory for third-party sources")
## Dependencies
find_package(Poco REQUIRED COMPONENTS Net Foundation)
find_package(Eigen3 REQUIRED)
Once it hits the first find_package is where I encounter the error:
Here is the code within FindPoco.cmake.
find_package(Poco COMPONENTS ${Poco_FIND_COMPONENTS} CONFIG QUIET)
if(Poco_FOUND)
return()
endif()
find_path(Poco_INCLUDE_DIR Poco/Poco.h)
mark_as_advanced(FORCE Poco_INCLUDE_DIR)
foreach(component ${Poco_FIND_COMPONENTS})
set(component_var "Poco_${component}_LIBRARY")
find_library(${component_var} Poco${component})
mark_as_advanced(FORCE ${component_var})
if(${component_var})
set(Poco_${component}_FOUND TRUE)
list(APPEND Poco_LIBRARIES ${component})
if(NOT TARGET Poco::${component})
add_library(Poco::${component} SHARED IMPORTED)
set_target_properties(Poco::${component} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${Poco_INCLUDE_DIR}
IMPORTED_LOCATION ${${component_var}}
)
endif()
endif()
endforeach()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Poco
FOUND_VAR Poco_FOUND
REQUIRED_VARS Poco_INCLUDE_DIR Poco_LIBRARIES
VERSION_VAR Poco_VERSION
HANDLE_COMPONENTS
)
I installed poco using vcpkg in a directory titled vcpkg. Within the vcpkg directory is the libfranka directory, which houses the CMakeLists.txt file that I compile in Visual Studio. Here is an image of that directory:
Finally, here is the tutorial that I am using: https://frankaemika.github.io/docs/installation_windows.html#building-from-source
EDIT:
Per the link I followed the instructions for solving the build dependencies and here is an image of that:
Then I ran the CMakeLists.txt again and in the CMake Settings this is what I see:
Note also that I ran through the install of poco again and I noticed this and am unsure if it could be the source of the problem or if it means nothing (again, this was the out put after running vcpkg install poco):
After this I still receive the same error.
Does anyone see what it is that I am doing incorrectly?
Thank you!

libigl not found when "cmake" to libigl on amazon linux

I tried install libigl. Although in this tutorial, it says that it does not need installation, my program not found the libraries.
In my local machine with Ubuntu, cmake works fine!
But in Amazon Linux, instance of EC2 not working.
I compile my project with:
cmake3 .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=~/out
And the Error is:
CMake Error at CMakeLists.txt:21 (message):
libigl not found --- You can download it using:
git clone --recursive https://github.com/libigl/libigl.git /home/ec2-user/closer-lambda/../libigl
closer-lamba is the folder of my c++ project
I tried with git clone, and copy paste library from my original project in Ubuntu to Amazon Linux (to into folder project, ec2-user folder, etc), but always I receive the same error.
My CMakeLists.txt :
cmake_minimum_required(VERSION 3.5)
include_directories(includes)
set(CMAKE_CXX_STANDARD 11)
project(closer LANGUAGES CXX)
find_package(aws-lambda-runtime REQUIRED)
find_package(AWSSDK COMPONENTS s3)
#LIBIGL
#LIBIGL
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
find_package(LIBIGL QUIET)
if (NOT LIBIGL_FOUND)
message(FATAL_ERROR "libigl not found --- You can download it using: \n git clone --recursive https://github.com/libigl/libigl.git ${PROJECT_SOURCE_DIR}/../libigl")
endif()
# Compilation flags: adapt to your needs
if(MSVC)
# Enable parallel compilation
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /bigobj")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR} )
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR} )
else()
# Libigl requires a modern C++ compiler that supports c++11
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "." )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
endif()
# libigl options: choose between header only and compiled static library
# Header-only is preferred for small projects. For larger projects the static build
# considerably reduces the compilation times
option(LIBIGL_USE_STATIC_LIBRARY "Use LibIGL as static library" OFF)
# add a customizable menu bar
option(LIBIGL_WITH_NANOGUI "Use Nanogui menu" OFF)
# libigl options: choose your dependencies (by default everything is OFF except opengl)
option(LIBIGL_WITH_VIEWER "Use OpenGL viewer" OFF)
option(LIBIGL_WITH_OPENGL "Use OpenGL" ON)
option(LIBIGL_WITH_OPENGL_GLFW "Use GLFW" ON)
option(LIBIGL_WITH_BBW "Use BBW" OFF)
option(LIBIGL_WITH_EMBREE "Use Embree" OFF)
option(LIBIGL_WITH_PNG "Use PNG" OFF)
option(LIBIGL_WITH_TETGEN "Use Tetgen" OFF)
option(LIBIGL_WITH_TRIANGLE "Use Triangle" ON)
option(LIBIGL_WITH_XML "Use XML" OFF)
option(LIBIGL_WITH_LIM "Use LIM" OFF)
option(LIBIGL_WITH_COMISO "Use CoMiso" OFF)
option(LIBIGL_WITH_MATLAB "Use Matlab" OFF) # This option is not supported yet
option(LIBIGL_WITH_MOSEK "Use MOSEK" OFF) # This option is not supported yet
option(LIBIGL_WITH_CGAL "Use CGAL" OFF)
if(LIBIGL_WITH_CGAL) # Do not remove or move this block, the cgal build system fails without it
find_package(CGAL REQUIRED)
set(CGAL_DONT_OVERRIDE_CMAKE_FLAGS TRUE CACHE BOOL "CGAL's CMAKE Setup is super annoying ")
include(${CGAL_USE_FILE})
endif()
# Adding libigl: choose the path to your local copy libigl
# This is going to compile everything you requested
#message(FATAL_ERROR "${PROJECT_SOURCE_DIR}/../libigl/cmake")
add_subdirectory("${LIBIGL_INCLUDE_DIR}/../shared/cmake" "libigl")
# libigl information
message("libigl includes: ${LIBIGL_INCLUDE_DIRS}")
message("libigl libraries: ${LIBIGL_LIBRARIES}")
message("libigl extra sources: ${LIBIGL_EXTRA_SOURCES}")
message("libigl extra libraries: ${LIBIGL_EXTRA_LIBRARIES}")
message("libigl definitions: ${LIBIGL_DEFINITIONS}")
#END LIBIGL
# Prepare the build environment
include_directories(${LIBIGL_INCLUDE_DIRS})
add_definitions(${LIBIGL_DEFINITIONS})
add_executable(${PROJECT_NAME} "main.cpp" ${LIBIGL_EXTRA_SOURCES} Colorizer.h Colorizer.cpp EdgeLeveler.cpp EdgeLeveler.h SawToothCleaner.cpp SawToothCleaner.h Utilities.cpp Utilities.h)
target_link_libraries(${PROJECT_NAME} PUBLIC
AWS::aws-lambda-runtime
${AWSSDK_LINK_LIBRARIES}
${LIBIGL_LIBRARIES}
${LIBIGL_EXTRA_LIBRARIES})
aws_lambda_package_target(${PROJECT_NAME})
I think to should compile libigl, but i tried and library blas not found.
Thank you!!!!
I fixed it
I forget copy the "cmake" folder, its contain:
"FindLIBIGL.cmake" in my case, libigl is in logal_libigl
# - Try to find the LIBIGL library
# Once done this will define
#
# LIBIGL_FOUND - system has LIBIGL
# LIBIGL_INCLUDE_DIR - **the** LIBIGL include directory
# LIBIGL_INCLUDE_DIRS - LIBIGL include directories
# LIBIGL_SOURCES - the LIBIGL source files
if(NOT LIBIGL_FOUND)
FIND_PATH(LIBIGL_INCLUDE_DIR igl/readOBJ.h
${PROJECT_SOURCE_DIR}/local_libigl/libigl
${PROJECT_SOURCE_DIR}/local_libigl/libigl/include
)
if(LIBIGL_INCLUDE_DIR)
set(LIBIGL_FOUND TRUE)
set(LIBIGL_INCLUDE_DIRS ${LIBIGL_INCLUDE_DIR} ${LIBIGL_INCLUDE_DIR}/../external/Singular_Value_Decomposition)
#set(LIBIGL_SOURCES
# ${LIBIGL_INCLUDE_DIR}/igl/viewer/Viewer.cpp
#)
endif()
endif()

Build Application using libpam0g-dev with cmake

I'm trying to build a C++ application which uses the library libpamg0-dev.
I installed it with the following command on my elementaryOS VM.
apt-get install libpam0g-dev
When I try to compile the application, the compiler spits out the following errors:
undefined reference to `pam_start`
undefined reference to `pam_authenticate`
undefined reference to `pam_end`
My CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.10)
project(application)
set(CMAKE_CXX_STANDARD 11)
INCLUDE_DIRECTORIES(/home/dnagl/dev/libs/restbed/distribution/include /usr/include/security)
LINK_DIRECTORIES(/home/dnagl/dev/libs/restbed/distribution/library /usr/lib/x86_64-linux-gnu)
add_executable(application main.cpp Utils/Json/Json.cpp Utils/Json/Json.h Utils/Stringhelper/Stringhelper.cpp Utils/Stringhelper/Stringhelper.h Utils/File/Filehelper.cpp Utils/File/Filehelper.h Utils/System/SystemHelper.cpp Utils/System/SystemHelper.h Controller/Info/InfoController.cpp Controller/Info/InfoController.h Rest/ResourceHandler/ResourceHandler.cpp Rest/ResourceHandler/ResourceHandler.h Controller/System/SystemController.cpp Controller/System/SystemController.h Rest/Log/RequestLogger.cpp Rest/Log/RequestLogger.h Controller/Authentication/AuthenticationController.cpp Controller/Authentication/AuthenticationController.h Controller/Log/LogController.cpp Controller/Log/LogController.h)
target_link_libraries(application restbed)
Maybe one of you knows how to link the library in the right way.
I have found a nice solution with find_package option from CMake. CMake provides a way to find packages/libraries with specified FindModule.cmake file.
A really good news is that there are a lot of existing module files. You can use this version to find PAM package on Linux. Put it to cmake/modules/ in your project folder and update your CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
project(restbed)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Notify CMake that we have module files to find packages/libs.
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
find_package(PAM REQUIRED)
# Check if we found PAM.
if (NOT PAM_FOUND)
message(FATAL_ERROR "PAM library was not found.")
endif ()
# Source configuration.
include_directories(
${PAM_INCLUDE_DIR}
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
set(EXECUTABLE_NAME "application")
# Add sources to this project's executable.
add_executable(${EXECUTABLE_NAME}
"main.cpp"
"Utils/Json/Json.cpp"
"Utils/Json/Json.h"
"Utils/Stringhelper/Stringhelper.cpp"
"Utils/Stringhelper/Stringhelper.h"
"Utils/File/Filehelper.cpp"
"Utils/File/Filehelper.h"
"Utils/System/SystemHelper.cpp"
"Utils/System/SystemHelper.h"
"Controller/Info/InfoController.cpp"
"Controller/Info/InfoController.h"
"Rest/ResourceHandler/ResourceHandler.cpp"
"Rest/ResourceHandler/ResourceHandler.h"
"Controller/System/SystemController.cpp"
"Controller/System/SystemController.h"
"Rest/Log/RequestLogger.cpp"
"Rest/Log/RequestLogger.h"
"Controller/Authentication/AuthenticationController.cpp"
"Controller/Authentication/AuthenticationController.h"
"Controller/Log/LogController.cpp"
"Controller/Log/LogController.h"
)
target_link_libraries(${EXECUTABLE_NAME}
${PAM_LIBRARIES}
)
set_target_properties(${EXECUTABLE_NAME} PROPERTIES LINKER_LANGUAGE CXX)
Hope this helps!

OpenCV_FOUND to FALSE so package "OpenCV" is considered to be NOT FOUND

I am having problems at the moment trying to get my cmake to see my opencv.
I have installed opencv and can run the some of the sample problems and some give the same error as the the error I get in my cmake file (when running the sample programs through terminal)
I have tried to change the environment variable path as described in
http://answers.opencv.org/question/35125/cmake-linking-error-opencv_found-to-false-ubuntu/
My bashrc file now looks like
CMAKE_PREFIX_PATH=/home/durham/Desktop/OpenCV/opencv-2.4.9:$CMAKE_PREFIX_PATH
CPATH=/home/durham/Desktop/OpenCV/opencv-2.4.9/include:$CPATH LD_LIBRARY_PATH=/home/durham/Desktop/OpenCV/opencv-2.4.9/lib:$LD_LIBRARY_PATH PATH=/home/durham/Desktop/OpenCV/opencv-2.4.9bin:$PATH
PKG_CONFIG_PATH=/home/durham/Desktop/OpenCV/opencv-2.4.9/lib/pkgconfig:$PKG_CONFIG_PATH
PYTHONPATH=/home/durham/Desktop/OpenCV/opencv-2.4.9/lib/python2.7/dist-packages:$PYTHONPATH
and the contents of /etc/ld.so.conf are
include /etc/ld.so.conf.d/*.conf
include /home/durham/Desktop/OpenCV/opencv-2.4.9
The cmake file I am trying to run looks like this
cmake_minimum_required(VERSION 2.6)
if(POLICY CMP0020) cmake_policy(SET CMP0020 NEW) endif(POLICY CMP0020)
SET(CMAKE_VERBOSE_MAKEFILE TRUE) SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/config)
ADD_DEFINITIONS(-DQT_THREAD_SUPPORT -D_REENTRANT -DQT_NO_DEBUG
-DIQRMODULE)
SET(QT_MT_REQUIRED TRUE) find_package(Qt5Widgets) FIND_PACKAGE(OpenCV REQUIRED)
IF(NOT DEFINED IQR_INCLUDE_DIR) set (IQR_INCLUDE_DIR "/usr/include/iqr") #default for linux ENDIF(NOT DEFINED IQR_INCLUDE_DIR)
IF(NOT EXISTS ${IQR_INCLUDE_DIR}) message(STATUS "not exists IQR_INCLUDE_DIR: ${IQR_INCLUDE_DIR}") set (IQR_INCLUDE_DIR $ENV{IQR_INCLUDE_DIR} CACHE PATH "" FORCE) IF(NOT EXISTS ${IQR_INCLUDE_DIR})
message(STATUS "IQR_INCLUDE_DIR set to ${IQR_INCLUDE_DIR}")
message(FATAL_ERROR "Please specify iqr include directory using IQR_INCLUDE_DIR env. variable") ENDIF(NOT EXISTS ${IQR_INCLUDE_DIR}) ENDIF(NOT EXISTS ${IQR_INCLUDE_DIR})
IF(WIN32) IF(NOT DEFINED IQR_LIB_DIR)
set (IQR_LIB_DIR $ENV{IQR_LIB_DIR} CACHE PATH "" FORCE) ENDIF(NOT DEFINED IQR_LIB_DIR)
IF(NOT EXISTS ${IQR_LIB_DIR})
message(FATAL_ERROR "Please specify phidgets include directory using IQR_LIB_DIR env. variable") ENDIF(NOT EXISTS ${IQR_LIB_DIR}) ENDIF(WIN32)
SET(libSrc
moduleArDroneBottomCamera.cpp
)
INCLUDE_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${IQR_INCLUDE_DIR} ${QT_INCLUDE_DIR} ${OPENCV_INCLUDE_DIR} ardrone_sdk/ ardrone_sdk/VP_SDK/ ardrone_sdk/VLIB/Stages/ ardrone_sdk/VP_SDK/VP_Os/ ardrone_sdk/VP_SDK/VP_Os/linux/ ardrone_sdk/VP_SDK/VP_Stages/ )
ADD_SUBDIRECTORY(ardrone_sdk)
ADD_LIBRARY(moduleArDroneBottomCamera SHARED ${libSrc})
IF(WIN32) set(IQR_LIBS "${IQR_LIB_DIR}/libIqrItem.dll") ENDIF(WIN32)
TARGET_LINK_LIBRARIES (moduleArDroneBottomCamera ${OPENCV_LIBRARIES} pc_ardrone ${QT_LIBRARIES} ${IQR_LIBS} )
qt5_use_modules(moduleArDroneBottomCamera Core Widgets Network)
SET_TARGET_PROPERTIES(moduleArDroneBottomCamera PROPERTIES PREFIX "")
IF(UNIX) set (IQR_INSTALL_DIR $ENV{HOME}) ENDIF(UNIX)
IF(WIN32) set (IQR_INSTALL_DIR $ENV{USERPROFILE}) ENDIF(WIN32)
INSTALL(TARGETS moduleArDroneBottomCamera LIBRARY DESTINATION ${IQR_INSTALL_DIR}/iqr/lib/Modules RUNTIME DESTINATION ${IQR_INSTALL_DIR}/iqr/lib/Modules )
But when I try to generate this using the cmake gui I get the following output (cant post images yet so its in the link)
http://postimg.org/image/4e553z6rh/
I am running Ubuntu 14.04. Any suggestions?
Thanks
D
Fast and dirty solution: try to install opencv (You know, make && sudo make install). After installation header files should be inc /usr/local/include and library files should be in /usr/local/lib .
The problem might lay somewhere ind FindOpenCV.cmake file, so You might as well try to understand what it is doing and maybe fix it - CMake syntax is fairly straightforward.
It might check in a default instalation location instead where it lies right now, or some rarely used environment variable.