libtins compile with arm-linux-gnueabi-g++ cmake error - c++

im facing a problem with cmake when trying to compile libtins library to embedded device using arm-linux-gnueabi-g++
i must say that when im compiling the library for linux (not embedded) the cmake works fine! and no error is shown! like in this toturial: compiling libtins with linux
but i need the cross compiler option so i did these steps:
first i installed the arm cross compiler with the apt get command, second, i downloaded the libtins master directory from the official github and i created a build dir and used the cmake command in the libtins cross compile toturial here :
libtins cross compile
i change it a bit so i can use my own arm compiler and the command is:
cmake ../ -DCMAKE_FIND_ROOT_PATH=/usr/lib/ -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY -DCMAKE_CXX_COMPILER=/usr/bin/arm-linux-gnueabi-g++ -DLIBTINS_ENABLE_WPA2=0 -DCROSS_COMPILING=1
and i get this error in the terminal:
-- The C compiler identification is GNU 8.2.0
-- The CXX compiler identification is GNU 9.2.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/arm-linux-gnueabi-g++
-- Check for working CXX compiler: /usr/bin/arm-linux-gnueabi-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Setting build type to 'RelWithDebInfo' as none was specified.
-- Build will generate a shared library. Use LIBTINS_BUILD_SHARED=0 to perform a static build
CMake Error at /usr/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find PCAP (missing: PCAP_LIBRARY)
Call Stack (most recent call first):
/usr/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
cmake/Modules/FindPCAP.cmake:46 (find_package_handle_standard_args)
CMakeLists.txt:61 (FIND_PACKAGE)
but i did a lot of resarch in the web and added this line -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu to the cmake command so i run this command in the terminal :
cmake ../ -DCMAKE_FIND_ROOT_PATH=/usr/lib/ -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY -DCMAKE_CXX_COMPILER=/usr/bin/arm-linux-gnueabi-g++ -DLIBTINS_ENABLE_WPA2=0 -DCROSS_COMPILING=1 -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu
and it seems to find pcap but now i get another error:
-- The C compiler identification is GNU 8.2.0
-- The CXX compiler identification is GNU 9.2.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/arm-linux-gnueabi-g++
-- Check for working CXX compiler: /usr/bin/arm-linux-gnueabi-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Setting build type to 'RelWithDebInfo' as none was specified.
-- Build will generate a shared library. Use LIBTINS_BUILD_SHARED=0 to perform a static build
-- Found PCAP: /usr/lib/x86_64-linux-gnu/libpcap.so
-- Performing Test PCAP_LINKS_SOLO
-- Performing Test PCAP_LINKS_SOLO - Failed
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Performing Test PCAP_NEEDS_THREADS
-- Performing Test PCAP_NEEDS_THREADS - Failed
CMake Error at cmake/Modules/FindPCAP.cmake:70 (message):
Couldn't determine how to link against libpcap
Call Stack (most recent call first):
CMakeLists.txt:61 (FIND_PACKAGE)
-- Configuring incomplete, errors occurred!
See also "/root/Desktop/libtins-master/build/CMakeFiles/CMakeOutput.log".
See also "/root/Desktop/libtins-master/build/CMakeFiles/CMakeError.log".
my cmakeLists file looks like this:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.1)
PROJECT(libtins)
OPTION(LIBTINS_BUILD_EXAMPLES "Build examples" ON)
OPTION(LIBTINS_BUILD_TESTS "Build tests" ON)
# Compile in release mode by default
IF(NOT CMAKE_BUILD_TYPE)
MESSAGE(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
SET(CMAKE_BUILD_TYPE RelWithDebInfo)
ELSE(NOT CMAKE_BUILD_TYPE)
MESSAGE(STATUS "Using specified '${CMAKE_BUILD_TYPE}' build type.")
ENDIF(NOT CMAKE_BUILD_TYPE)
# Compilation flags.
IF(MSVC)
# Don't always use Wall, since VC's /Wall is ridiculously verbose.
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
# Disable VC secure checks, since these are not really issues.
ADD_DEFINITIONS("-D_CRT_SECURE_NO_WARNINGS=1")
ADD_DEFINITIONS("-D_SCL_SECURE_NO_WARNINGS=1")
ADD_DEFINITIONS("-DNOGDI=1")
ELSE()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
ENDIF()
IF(APPLE)
# This is set to ON as of policy CMP0042
SET(CMAKE_MACOSX_RPATH ON)
ENDIF()
# Build output checks
OPTION(LIBTINS_BUILD_SHARED "Build libtins as a shared library." ON)
IF(LIBTINS_BUILD_SHARED)
MESSAGE(
STATUS
"Build will generate a shared library. "
"Use LIBTINS_BUILD_SHARED=0 to perform a static build"
)
SET(LIBTINS_TYPE SHARED)
ELSE(LIBTINS_BUILD_SHARED)
MESSAGE(STATUS "Build will generate a static library.")
SET(LIBTINS_TYPE STATIC)
ADD_DEFINITIONS("-DTINS_STATIC=1")
ENDIF(LIBTINS_BUILD_SHARED)
# The version number.
SET(TINS_VERSION_MAJOR 4)
SET(TINS_VERSION_MINOR 3)
SET(TINS_VERSION_PATCH 0)
SET(LIBTINS_VERSION "${TINS_VERSION_MAJOR}.${TINS_VERSION_MINOR}")
# Required Packages
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
# Allow disabling packet capture mechanism
OPTION(LIBTINS_ENABLE_PCAP "Enable capturing packets via libpcap" ON)
# Look for libpcap
IF(LIBTINS_ENABLE_PCAP)
FIND_PACKAGE(PCAP REQUIRED)
SET(TINS_HAVE_PCAP ON)
ENDIF()
# Set some Windows specific flags
IF(WIN32)
# We need to link against these libs
SET(LIBTINS_OS_LIBS Ws2_32.lib Iphlpapi.lib)
# Add the NOMINMAX macro to avoid Windows' min and max macros.
ADD_DEFINITIONS(-DNOMINMAX)
# MinWG need some extra definitions to compile properly (WIN32 for PCAP and WIN32_WINNT version for ws2tcpip.h)
IF(MINGW)
ADD_DEFINITIONS(-DWIN32)
MACRO(get_WIN32_WINNT version)
IF (WIN32 AND CMAKE_SYSTEM_VERSION)
SET(ver ${CMAKE_SYSTEM_VERSION})
STRING(REPLACE "." "" ver ${ver})
STRING(REGEX REPLACE "([0-9])" "0\\1" ver ${ver})
SET(${version} "0x${ver}")
ENDIF()
ENDMACRO()
get_WIN32_WINNT(ver)
ADD_DEFINITIONS(-D_WIN32_WINNT=${ver})
ENDIF(MINGW)
ENDIF(WIN32)
INCLUDE(ExternalProject)
# *******************
# Compilation options
# *******************
# Always check for C++ features
INCLUDE(CheckCXXFeatures)
IF(HAS_GCC_BUILTIN_SWAP)
SET(TINS_HAVE_GCC_BUILTIN_SWAP ON)
ENDIF()
# C++11 support
OPTION(LIBTINS_ENABLE_CXX11 "Compile libtins with c++11 features" ON)
IF(LIBTINS_ENABLE_CXX11)
# We only use declval and decltype on gcc/clang as VC fails to build that code,
# at least on VC2013
IF(HAS_CXX11_RVALUE_REFERENCES AND HAS_CXX11_FUNCTIONAL AND HAS_CXX11_CHRONO AND
HAS_CXX11_NOEXCEPT AND ((HAS_CXX11_DECLVAL AND HAS_CXX11_DECLTYPE) OR MSVC))
SET(TINS_HAVE_CXX11 ON)
MESSAGE(STATUS "Enabling C++11 features")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_COMPILER_FLAGS}")
ELSE()
MESSAGE(WARNING "The compiler doesn't support the necessary C++11 features. "
"Disabling C++11 on this build")
ENDIF()
ELSE(LIBTINS_ENABLE_CXX11)
MESSAGE(
WARNING
"Disabling C++11 features. Use LIBTINS_ENABLE_CXX11=1 to enable them. "
"Unless you are using an old compiler, you should enable this option, "
"as it increases the library's performance")
ENDIF(LIBTINS_ENABLE_CXX11)
# IEEE 802.11 and WPA2 decryption support
OPTION(LIBTINS_ENABLE_DOT11 "Compile libtins with IEEE 802.11 support" ON)
OPTION(LIBTINS_ENABLE_WPA2 "Compile libtins with WPA2 decryption features (requires OpenSSL)" ON)
IF(LIBTINS_ENABLE_DOT11)
SET(TINS_HAVE_DOT11 ON)
MESSAGE(STATUS "Enabling IEEE 802.11 support.")
IF(LIBTINS_ENABLE_WPA2)
FIND_PACKAGE(OpenSSL)
IF(OPENSSL_FOUND)
SET(TINS_HAVE_WPA2_DECRYPTION ON)
MESSAGE(STATUS "Enabling WPA2 decryption support.")
ELSE()
MESSAGE(WARNING "Disabling WPA2 decryption support since OpenSSL was not found")
# Default this to empty strings
SET(OPENSSL_INCLUDE_DIR "")
SET(OPENSSL_LIBRARIES "")
ENDIF()
ELSE(LIBTINS_ENABLE_WPA2)
MESSAGE(STATUS "Disabling WPA2 decryption support.")
ENDIF(LIBTINS_ENABLE_WPA2)
ENDIF(LIBTINS_ENABLE_DOT11)
# Optionally enable TCPIP classes (on by default)
OPTION(LIBTINS_ENABLE_TCPIP "Enable TCPIP classes" ON)
IF(LIBTINS_ENABLE_TCPIP AND TINS_HAVE_CXX11)
SET(TINS_HAVE_TCPIP ON)
MESSAGE(STATUS "Enabling TCPIP classes")
ELSE()
SET(TINS_HAVE_TCPIP OFF)
MESSAGE(STATUS "Disabling TCPIP classes")
ENDIF()
# Search for libboost
FIND_PACKAGE(Boost)
# Optionally enable the ACK tracker (on by default)
OPTION(LIBTINS_ENABLE_ACK_TRACKER "Enable TCP ACK tracking support" ON)
IF(LIBTINS_ENABLE_ACK_TRACKER AND TINS_HAVE_CXX11)
IF (Boost_FOUND)
MESSAGE(STATUS "Enabling TCP ACK tracking support.")
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
SET(TINS_HAVE_ACK_TRACKER ON)
ELSE()
MESSAGE(WARNING "Disabling ACK tracking support as boost.icl was not found")
SET(TINS_HAVE_ACK_TRACKER OFF)
ENDIF()
ELSE()
SET(TINS_HAVE_ACK_TRACKER OFF)
MESSAGE(STATUS "Disabling ACK tracking support")
ENDIF()
# Optionally enable the TCP stream custom data (on by default)
OPTION(LIBTINS_ENABLE_TCP_STREAM_CUSTOM_DATA "Enable TCP stream custom data support" ON)
IF(LIBTINS_ENABLE_TCP_STREAM_CUSTOM_DATA AND TINS_HAVE_CXX11)
IF (Boost_FOUND)
MESSAGE(STATUS "Enabling TCP stream custom data support.")
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
SET(TINS_HAVE_TCP_STREAM_CUSTOM_DATA ON)
ELSE()
MESSAGE(WARNING "Disabling TCP stream custom data support as boost.any was not found")
SET(TINS_HAVE_TCP_STREAM_CUSTOM_DATA OFF)
ENDIF()
ELSE()
SET(TINS_HAVE_TCP_STREAM_CUSTOM_DATA OFF)
MESSAGE(STATUS "Disabling TCP stream custom data support")
ENDIF()
OPTION(LIBTINS_ENABLE_WPA2_CALLBACKS "Enable WPA2 callback interface" ON)
IF(LIBTINS_ENABLE_WPA2_CALLBACKS AND TINS_HAVE_WPA2_DECRYPTION AND TINS_HAVE_CXX11)
SET(STATUS "Enabling WPA2 callback interface")
SET(TINS_HAVE_WPA2_CALLBACKS ON)
ENDIF()
# Use pcap_sendpacket to send l2 packets rather than raw sockets
IF(WIN32)
SET(USE_PCAP_SENDPACKET_DEFAULT ON)
ELSE(WIN32)
SET(USE_PCAP_SENDPACKET_DEFAULT OFF)
ENDIF(WIN32)
OPTION(LIBTINS_USE_PCAP_SENDPACKET "Use pcap_sendpacket to send l2 packets"
${USE_PCAP_SENDPACKET_DEFAULT})
IF(LIBTINS_ENABLE_PCAP AND LIBTINS_USE_PCAP_SENDPACKET)
SET(TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET ON)
MESSAGE(STATUS "Using pcap_sendpacket to send l2 packets.")
ENDIF()
# Add a target to generate API documentation using Doxygen
FIND_PACKAGE(Doxygen QUIET)
IF(DOXYGEN_FOUND)
CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
#ONLY
)
ADD_CUSTOM_TARGET(
docs
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
ENDIF(DOXYGEN_FOUND)
# Configuration file
CONFIGURE_FILE(
"${PROJECT_SOURCE_DIR}/include/tins/config.h.in"
"${PROJECT_SOURCE_DIR}/include/tins/config.h"
)
IF (NOT CMAKE_INSTALL_LIBDIR)
SET(CMAKE_INSTALL_LIBDIR lib)
ENDIF()
IF (NOT CMAKE_INSTALL_BINDIR)
SET(CMAKE_INSTALL_BINDIR bin)
ENDIF()
# The library output directory
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
# Support for pkg-config
SET(pkgconfig_prefix ${CMAKE_INSTALL_PREFIX})
SET(pkgconfig_exec_prefix ${CMAKE_INSTALL_PREFIX})
SET(pkgconfig_libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
SET(pkgconfig_version ${LIBTINS_VERSION})
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libtins.pc.in
${CMAKE_CURRENT_BINARY_DIR}/libtins.pc #ONLY)
INSTALL(
FILES
${CMAKE_CURRENT_BINARY_DIR}/libtins.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
# Confiugure the uninstall script
CONFIGURE_FILE(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE #ONLY
)
# Add uninstall target
ADD_CUSTOM_TARGET(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
# ******************
# Add subdirectories
# ******************
ADD_SUBDIRECTORY(src)
IF(LIBTINS_BUILD_EXAMPLES)
IF(LIBTINS_ENABLE_PCAP)
ADD_SUBDIRECTORY(examples)
ELSE()
MESSAGE(STATUS "Not building examples as pcap support is disabled")
ENDIF()
ENDIF()
IF(LIBTINS_BUILD_TESTS)
# Only include googletest if the git submodule has been fetched
IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/googletest/CMakeLists.txt")
# Enable tests and add the test directory
MESSAGE(STATUS "Tests have been enabled")
SET(GOOGLETEST_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
SET(GOOGLETEST_INCLUDE ${GOOGLETEST_ROOT}/googletest/include)
SET(GOOGLETEST_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/googletest)
SET(GOOGLETEST_LIBRARY ${GOOGLETEST_BINARY_DIR}/googletest)
ExternalProject_Add(
googletest
DOWNLOAD_COMMAND ""
SOURCE_DIR ${GOOGLETEST_ROOT}
BINARY_DIR ${GOOGLETEST_BINARY_DIR}
CMAKE_CACHE_ARGS "-DBUILD_GTEST:bool=ON" "-DBUILD_GMOCK:bool=OFF"
"-Dgtest_force_shared_crt:bool=ON"
"-DCMAKE_CXX_COMPILER:path=${CMAKE_CXX_COMPILER}"
INSTALL_COMMAND ""
)
# Make sure we build googletest before anything else
ADD_DEPENDENCIES(tins googletest)
ENABLE_TESTING()
ADD_SUBDIRECTORY(tests)
ELSE()
MESSAGE(STATUS "googletest git submodule is absent. Run `git submodule init && git submodule update` to get it")
ENDIF()
ENDIF()
# **********************************
# CMake project configuration export
# **********************************
if(UNIX)
set(CONF_CMAKE_INSTALL_DIR lib/cmake/libtins)
else()
set(CONF_CMAKE_INSTALL_DIR CMake)
endif()
# Add all targets to the build-tree export set
EXPORT(
TARGETS tins
FILE "${PROJECT_BINARY_DIR}/libtinsTargets.cmake"
)
# Export the package for use from the build-tree
# (this registers the build-tree with a global CMake-registry)
EXPORT(PACKAGE libtins)
# Create the libtinsConfig.cmake and libtinsConfigVersion.cmake files
# for the build tree
SET(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include")
CONFIGURE_FILE(
cmake/libtinsConfig.cmake.in
"${PROJECT_BINARY_DIR}/libtinsConfig.cmake" #ONLY
)
CONFIGURE_FILE(
cmake/libtinsConfigVersion.cmake.in
"${PROJECT_BINARY_DIR}/libtinsConfigVersion.cmake" #ONLY
)
# Install the libtinsConfig.cmake and libtinsConfigVersion.cmake
INSTALL(
FILES
"${PROJECT_BINARY_DIR}/libtinsConfig.cmake"
"${PROJECT_BINARY_DIR}/libtinsConfigVersion.cmake"
DESTINATION ${CONF_CMAKE_INSTALL_DIR}
COMPONENT dev
)
# Install the export set for use with the install-tree
INSTALL(
EXPORT libtinsTargets
DESTINATION ${CONF_CMAKE_INSTALL_DIR}
COMPONENT dev
)
i didnt touch it and im sure that the solution needs to be in this file and im a little lost with cmake files so any help will be great!

Related

How can I use cmake's find_packge(OpenCV) on gitlab

I am using cmake to compile a c++ and OpenCV project. and I want to run my tests on Gitlab but got some errors. My question is: How can I use find_package(OpenCV REQUIRED) in CMakeLists.txt on gitlab? this is my CMakeLists.txt: (by the way, it works correct locally on my Linux machine .)
# cmake minimum requiredments
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
# project name
project(imageEnhancer LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF) # disable compiler specific extensions
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Catch2 QUIET)
if (NOT Catch2_FOUND)
message("Catch2 not found")
include(FetchContent)
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.11.0
)
FetchContent_MakeAvailable(catch2)
list(APPEND CMAKE_MODULE_PATH "${catch2_SOURCE_DIR}/contrib")
endif()
# search for OpenMP
find_package(OpenMP REQUIRED)
# search for OpenCV
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
# add a library to the project using the specified source files
add_library(opencv STATIC include/opencvtest.h src/opencvtest.cpp)
# PUBLIC -> targets that link to this target get that include directory
target_include_directories(opencv PUBLIC include PRIVATE src)
# link to the imported target provided by the FindOpenMP moudule
target_link_libraries(opencv PUBLIC OpenMP::OpenMP_CXX)
# Create executable with name imageEnhancer
add_executable(imageEnhancer main.cpp)
# linke to the imported target provided by the FindOpenMP module
target_link_libraries(imageEnhancer PUBLIC OpenMP::OpenMP_CXX ${OpenCV_LIBS})
but I got the following error:
$ cd project
$ mkdir -p build
$ cd build
$ cmake ..
-- The CXX compiler identification is GNU 10.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Catch2 not found
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
CMake Error at CMakeLists.txt:31 (find_package):
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OpenCV", but
CMake did not find one.
Could not find a package configuration file provided by "OpenCV" with any
of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/builds/davood_hadiannejad/algorithm-engineering-lab/project/build/CMakeFiles/CMakeOutput.log".
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1
and I tried to solve it like, but it didn't work
if (NOT Catch2_FOUND)
message("Catch2 not found")
include(FetchContent)
FetchContent_Declare(
OpenCV
GIT_REPOSITORY https://github.com/opencv/opencv.git
)
FetchContent_MakeAvailable(OpenCV)
list(APPEND CMAKE_MODULE_PATH "${OpenCV_SOURCE_DIR}/contrib")
endif()
any suggestion? thanks in advance

cmake error for header-only library: `include could not find load file`

I've been trying to change a makefile c++ project into a cmake project, and I've been having som difficulty. cmake seems to be looking for stuff in /usr/local/lib/ instead of /usr/local/include/ and I'm not sure why that is.
This library is header-only, and so I've been following this tutorial My header-only library in include seems to "build" fine, but I keep getting the following error when I try to generate a makefile to build my example program:
me:~/pf/examples/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /usr/local/lib/cmake/pf/pfConfig.cmake:27 (include):
include could not find load file:
/usr/local/lib/cmake/pf/pf_exampleTargets.cmake
Call Stack (most recent call first):
CMakeLists.txt:15 (find_package)
examples/CMakeLists.txt creates another fresh project:
project(pf_example)
cmake_minimum_required (VERSION 3.12)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_STANDARD 17)
# "install" pf
find_package(pf CONFIG REQUIRED)
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
file(GLOB SOURCES ${PROJECT_NAME}/*.{h,cpp})
message("${SOURCES}")
add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} pf::pf)
The root directory CMakeLists.txt file is more complicated. It's the one that was adapted from the tutorial I mentioned above:
cmake_minimum_required(VERSION 3.12)
project("pf" VERSION 1.0.1
DESCRIPTION "A header only c++ template library for fast particle filtering."
HOMEPAGE_URL "https://github.com/tbrown122387/pf")
include(GNUInstallDirs)
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(
${PROJECT_NAME}
INTERFACE $<BUILD_INTERFACE:${${PROJECT_NAME}_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}_Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
include(CMakePackageConfigHelpers)
write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
install(EXPORT ${PROJECT_NAME}_Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include DESTINATION include)
To install this header only library, before I try to build the examples project, I typed the following commands into the command line:
cd ~/pf
mkdir build
cd build/
cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/include
sudo cmake --build . --config Release --target install -- -j $(nproc)
I didn't post it, but there's also a file cmake/pfconfig.cmake.in that is verbatim copied from the tutorial above.
Your install prefix is specified as /usr/local/include so the files would be installed as:
headers into /usr/local/include/include
libraries into /usr/local/include/libs
cmake stuff into /usr/local/include/share/${PROJECT_NAME}/cmake
Those paths are just wrong. Just set CMAKE_INSTALL_PREFIX=/usr/local (ie. remove include) and install it inside /usr/local/ tree.
A few took care of this issue.
in CMakeLists.txt change install(DIRECTORY ${PROJECT_SOURCE_DIR}/include DESTINATION include) to install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/pf DESTINATION include) so the files don't clutter up the installation locations. This also requires creating pf/include/pf and moving all the files in pf/include to pf/include/pf.
Follow advice in #KamilCuk's answer.
In examples/CMakeLists.txt change file(GLOB SOURCES ${PROJECT_NAME}/*.{h,cpp}) to file(GLOB SOURCES ${CMAKE_SOURCE_DIR}/*.h ${CMAKE_SOURCE_DIR}/*.cpp)
Also note that my /usr/local/lib and /usr/local/include were quite cluttered up due to my numerous earlier failed attempts, so I deleted a bunch of files in there and re-installed fresh.

Vcpkg Pango CMake build fails missing header file

I am trying to install Wt using vcpkg, and pango is one of the dependencies. However, I am having serious issues trying to make it build correctly. Here is what the terminal outputs:
Starting package 1/2: pango:x64-osx
Building package pango[core]:x64-osx...
-- Using cached /Users/jackhogan/Desktop/Code/Utilities/vcpkg/downloads/pango-1.40.11.tar.xz
-- Using source at /Users/jackhogan/Desktop/Code/Utilities/vcpkg/buildtrees/pango/src/1.40.11-f997ae867d
-- Configuring x64-osx-dbg
-- Configuring x64-osx-rel
-- Building x64-osx-dbg
CMake Error at scripts/cmake/vcpkg_execute_build_process.cmake:136 (message):
Command failed: /Users/jackhogan/Desktop/Code/Utilities/vcpkg/downloads/tools/cmake-3.17.2-osx/cmake-3.17.2-Darwin-x86_64/CMake.app/Contents/bin/cmake --build . --config Debug --target install -- -v
Working Directory: /Users/jackhogan/Desktop/Code/Utilities/vcpkg/buildtrees/pango/x64-osx-dbg
See logs for more information:
/Users/jackhogan/Desktop/Code/Utilities/vcpkg/buildtrees/pango/install-x64-osx-dbg-out.log
Call Stack (most recent call first):
scripts/cmake/vcpkg_build_cmake.cmake:91 (vcpkg_execute_build_process)
scripts/cmake/vcpkg_install_cmake.cmake:24 (vcpkg_build_cmake)
ports/pango/portfile.cmake:25 (vcpkg_install_cmake)
scripts/ports.cmake:76 (include)
Error: Building package pango:x64-osx failed with: BUILD_FAILED
Please ensure you're using the latest portfiles with `.\vcpkg update`, then
submit an issue at https://github.com/Microsoft/vcpkg/issues including:
Package: pango:x64-osx
Vcpkg version: 2020.02.04-unknownhash
Additionally, attach any relevant sections from the log files above.
Here is the out file the terminal references:
-- The C compiler identification is AppleClang 11.0.3.11030032
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Link-time dependencies:
-- /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib/libintl.a
-- /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib/libglib-2.0.a
-- /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib/libgobject-2.0.a
-- /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib/libgmodule-2.0.a
-- /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib/libcairod.a
-- /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib/libcairo-gobjectd.a
-- /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib/libfreetyped.a
-- /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib/libfontconfig.a
-- /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib/libharfbuzz.a
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/jackhogan/Desktop/Code/Utilities/vcpkg/buildtrees/pango/x64-osx-dbg
Here is the CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
project(pango C)
set(PANGO_LIB_SUFFIX 1.0)
set(PANGO_DLL_SUFFIX 1)
set(GLIB_LIB_VERSION 2.0)
if(WIN32)
configure_file(./config.h.win32 ${CMAKE_CURRENT_BINARY_DIR}/config.h COPYONLY)
else()
configure_file(./config.h.unix ${CMAKE_CURRENT_BINARY_DIR}/config.h COPYONLY)
endif()
if (WIN32)
# Set utf-8 charset to avoid compile error C2001
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8")
endif()
add_definitions(-DHAVE_CONFIG_H)
include_directories(. ./pango ${CMAKE_CURRENT_BINARY_DIR})
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
# find libintl
find_path(LIBINTL_INCLUDE_DIR libintl.h)
find_library(LIBINTL_LIBRARY NAMES libintl intl)
endif()
# find glib
find_path(GLIB_INCLUDE_DIR glib.h)
find_library(GLIB_GLIB_LIBRARY glib-${GLIB_LIB_VERSION})
find_library(GLIB_GOBJECT_LIBRARY gobject-${GLIB_LIB_VERSION})
find_library(GLIB_GMODULE_LIBRARY gmodule-${GLIB_LIB_VERSION})
set(GLIB_LIBRARIES ${GLIB_GLIB_LIBRARY} ${GLIB_GOBJECT_LIBRARY} ${GLIB_GMODULE_LIBRARY})
# find cairo
find_path(CAIRO_INCLUDE_DIR cairo.h)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(CAIRO_SUFFIX d)
endif()
find_library(CAIRO_LIBRARY
NAMES
cairo${CAIRO_SUFFIX}
cairo-static${CAIRO_SUFFIX})
find_library(CAIRO_GOBJECT_LIBRARY cairo-gobject${CAIRO_SUFFIX})
set(CAIRO_LIBRARIES ${CAIRO_LIBRARY} ${CAIRO_GOBJECT_LIBRARY})
# find fontconfig
find_path(FONTCONFIG_INCLUDE_DIR fontconfig/fontconfig.h)
find_library(FONTCONFIG_LIBRARY fontconfig)
# find freetype
find_path(FREETYPE_INCLUDE_DIR ft2build.h)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(FT_SUFFIX d)
endif()
find_library(FREETYPE_LIBRARY freetype${FT_SUFFIX})
# find harfbuzz
find_path(HARFBUZZ_INCLUDE_DIR harfbuzz/hb.h)
find_library(HARFBUZZ_LIBRARY harfbuzz)
if (APPLE)
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
link_libraries(${COREFOUNDATION_LIBRARY})
endif()
set(FONT_INCLUDE_DIRS ${FREETYPE_INCLUDE_DIR} ${FONTCONFIG_INCLUDE_DIR} ${HARFBUZZ_INCLUDE_DIR}/harfbuzz)
set(FONT_LIBRARIES ${FREETYPE_LIBRARY} ${FONTCONFIG_LIBRARY} ${HARFBUZZ_LIBRARY})
macro(pango_add_module MODULE_NAME)
add_library(${MODULE_NAME} ${ARGN})
target_include_directories(${MODULE_NAME} PRIVATE ${GLIB_INCLUDE_DIR} ${LIBINTL_INCLUDE_DIR})
target_link_libraries(${MODULE_NAME} ${LIBINTL_LIBRARY} ${GLIB_LIBRARIES})
target_compile_definitions(${MODULE_NAME} PRIVATE
G_LOG_DOMAIN="Pango" PANGO_ENABLE_BACKEND PANGO_ENABLE_ENGINE
G_DISABLE_SINGLE_INCLUDES SYSCONFDIR="/dummy/etc" LIBDIR="/dummy/lib")
target_compile_definitions(${MODULE_NAME} PRIVATE HAVE_CAIRO_FREETYPE=1)
set_target_properties(${MODULE_NAME} PROPERTIES
DEFINE_SYMBOL PANGO_EXPORTS
OUTPUT_NAME ${MODULE_NAME}-${PANGO_DLL_SUFFIX}
ARCHIVE_OUTPUT_NAME ${MODULE_NAME}-${PANGO_LIB_SUFFIX})
install(TARGETS ${MODULE_NAME} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib)
endmacro()
pango_add_module(pango
pango/break-arabic.c
pango/break-indic.c
pango/mini-fribidi/fribidi.c
pango/mini-fribidi/fribidi_char_type.c
pango/mini-fribidi/fribidi_types.c
pango/break.c
pango/ellipsize.c
pango/fonts.c
pango/glyphstring.c
pango/modules.c
pango/pango-attributes.c
pango/pango-bidi-type.c
pango/pango-color.c
pango/pango-context.c
pango/pango-coverage.c
pango/pango-emoji.c
pango/pango-engine.c
pango/pango-fontmap.c
pango/pango-fontset.c
pango/pango-glyph-item.c
pango/pango-gravity.c
pango/pango-item.c
pango/pango-language.c
pango/pango-layout.c
pango/pango-markup.c
pango/pango-matrix.c
pango/pango-renderer.c
pango/pango-script.c
pango/pango-tabs.c
pango/pango-utils.c
pango/reorder-items.c
pango/shape.c
pango/pango-enum-types.c)
if(WIN32)
pango_add_module(pangowin32
pango/pangowin32.c
pango/pangowin32-fontcache.c
pango/pangowin32-fontmap.c
pango/pangowin32-shape.c)
target_link_libraries(pangowin32 usp10 pango gdi32)
endif()
pango_add_module(pangoft2
pango/pangofc-font.c
pango/pangofc-fontmap.c
pango/pangofc-decoder.c
pango/pangofc-shape.c
pango/pangoft2.c
pango/pangoft2-fontmap.c
pango/pangoft2-render.c
pango/pango-ot-buffer.c
pango/pango-ot-info.c
pango/pango-ot-ruleset.c
pango/pango-ot-tag.c)
target_link_libraries(pangoft2 pango ${FONT_LIBRARIES})
target_include_directories(pangoft2 PRIVATE ${FONT_INCLUDE_DIRS})
list(APPEND PANGO_CAIRO_SOURCES
pango/pangocairo-fcfont.c
pango/pangocairo-fcfontmap.c
pango/pangocairo-context.c
pango/pangocairo-font.c
pango/pangocairo-fontmap.c
pango/pangocairo-render.c)
if(WIN32)
list(APPEND PANGO_CAIRO_SOURCES
pango/pangocairo-win32font.c
pango/pangocairo-win32fontmap.c)
endif()
pango_add_module(pangocairo ${PANGO_CAIRO_SOURCES})
list(APPEND PANGO_CAIRO_LIBRARIES ${CAIRO_LIBRARIES} pango pangoft2 ${FONT_LIBRARIES})
if (WIN32)
list(APPEND PANGO_CAIRO_LIBRARIES pangowin32)
endif()
target_link_libraries(pangocairo ${PANGO_CAIRO_LIBRARIES})
target_include_directories(pangocairo PRIVATE ${CAIRO_INCLUDE_DIR} ${FONT_INCLUDE_DIRS})
if(NOT PANGO_SKIP_HEADERS)
install(FILES
pango/pango.h
pango/pango-attributes.h
pango/pango-bidi-type.h
pango/pango-break.h
pango/pango-context.h
pango/pango-coverage.h
pango/pango-engine.h
pango/pango-font.h
pango/pango-fontmap.h
pango/pango-fontset.h
pango/pango-glyph.h
pango/pango-glyph-item.h
pango/pango-gravity.h
pango/pango-item.h
pango/pango-language.h
pango/pango-layout.h
pango/pango-matrix.h
pango/pango-modules.h
pango/pango-renderer.h
pango/pango-script.h
pango/pango-tabs.h
pango/pango-types.h
pango/pango-utils.h
pango/pango-version-macros.h
pango/pangocairo.h
pango/pangowin32.h
pango/pango-features.h
pango/pango-enum-types.h
pango/pangofc-decoder.h
pango/pangofc-font.h
pango/pangofc-fontmap.h
pango/pango-ot.h
pango/pangoft2.h
DESTINATION include/pango)
endif()
message(STATUS "Link-time dependencies:")
message(STATUS " " ${LIBINTL_LIBRARY})
foreach(GL ${GLIB_LIBRARIES})
message(STATUS " " ${GL})
endforeach()
foreach(CL ${CAIRO_LIBRARIES})
message(STATUS " " ${CL})
endforeach()
foreach(FL ${FONT_LIBRARIES})
message(STATUS " " ${FL})
endforeach()
What could the problem be and how could I solve it? Vcpkg uses Clang but I also have GCC installed, so I could switch to it if necessary.
UPDATE
I ran some commands and found out that it couldn't find hb-glib.h. However, I already have glib and harfbuzz installed. I am even able to find the missing header file. What could be the cause of this issue?
Well, contrary to my expectations, just copying hb-glib.h to the pango source folder and building worked.

CMake Linking Static Library and Glib Errors

I have a pretty novice understanding of how Cmake works. I am have a project that includes a static library that in turn relies on glib. I am missing something that is causing a lot of undefined references to glib features like those below. I am working in Linux Ubuntu and have Cmake 3.5
../Gobbledegook/src/libggk.a(libggk_a-Gobbledegook.o): In function `ggkWait':
/home/ubuntu/visionpro-device-xray/src/user_device_interface/Gobbledegook/src/Gobbledegook.cpp:384: undefined reference to `g_set_print_handler'
/home/ubuntu/visionpro-device-xray/src/user_device_interface/Gobbledegook/src/Gobbledegook.cpp:385: undefined reference to `g_set_printerr_handler'
/home/ubuntu/visionpro-device-xray/src/user_device_interface/Gobbledegook/src/Gobbledegook.cpp:386: undefined reference to `g_log_set_default_handler'
Here is my Cmake file where I tried just building the library myself - without linking the static library. The library I am trying to use/include is https://github.com/nettlep/gobbledegook.
cmake_minimum_required(VERSION 3.2.2)
project(TestBLE)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -I/usr/include/glib-2.0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/lib/aarch64-linux-gnu/glib-2.0/include")
find_package(PkgConfig REQUIRED)
pkg_search_module(GLIB REQUIRED glib-2.0)
include_directories(${GLIB_INCLUDE_DIRS})
link_directories(${GLIB_LIBRARY_DIRS})
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# Gets all the header/source files in current directory
file(GLOB SOURCES "*.cpp")
file(GLOB HEADERS "*.h")
file(GLOB GGK_SOURCES "Gobbledegook/src/*.cpp")
file(GLOB GGK_HEADERS "Gobbledegook/src/*.h")
add_executable(
${PROJECT_NAME}
${SOURCES}
${HEADERS}
${CMAKE_SOURCE_DIR}/Gobbledegook/include/Gobbledegook.h
${GGK_SOURCES}
${GGK_HEADERS}
)
target_link_libraries(
${PROJECT_NAME}
${GLIB_LIBRARIES}
Threads::Threads
)
Here is my CMake file trying to link the static library libggk.a built with the ./configure && make inside of the Gobbledegook library.
cmake_minimum_required(VERSION 3.2.2)
project(TestBLE)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -I/usr/include/glib-2.0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/lib/aarch64-linux-gnu/glib-2.0/include")
find_package(PkgConfig REQUIRED)
pkg_search_module(GLIB REQUIRED glib-2.0)
include_directories(${GLIB_INCLUDE_DIRS})
link_directories(${GLIB_LIBRARY_DIRS})
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# Gets all the header/source files in current directory
file(GLOB SOURCES "*.cpp")
file(GLOB HEADERS "*.h")
add_executable(
${PROJECT_NAME}
${SOURCES}
${HEADERS}
${CMAKE_SOURCE_DIR}/Gobbledegook/include/Gobbledegook.h
)
target_link_libraries(
${PROJECT_NAME}
${GLIB_LIBRARIES}
Threads::Threads
${CMAKE_SOURCE_DIR}/Gobbledegook/src/libggk.a
)
I keep the undefined references in either case. Appreciate the help guys, I've been scouring the forums for a hint or an explanation.
EDIT:
here is my directory setup
project
|---------CMakeLists.txt
|---------build
|---------bluetest.cpp
|---------Gobbledegook
| |-----------include
| | |------Gobbldegook.h
| |-----------src
| | |------${all_the_source/header_files}
| | |------libggk.a
EDIT 2:
Modified Cmake to show prints
cmake_minimum_required(VERSION 3.2.2)
project(TestBLE)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB REQUIRED glib-2.0)
include_directories(Gobbledegook/include)
include_directories(${GLIB_INCLUDE_DIRS})
link_directories(${GLIB_LIBRARIES_DIRS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GLIB_CFLAGS}")
message(WARNING "GLIB_LIBRARIES: ${GLIB_LIBRARIES}")
message(WARNING "GLIB_LIBRARY_DIRS: ${GLIB_LIBRARY_DIRS}")
message(WARNING "GLIB_LDFLAGS: ${GLIB_LDFLAGS}")
message(WARNING "GLIB_LDFLAGS_OTHER: ${GLIB_LDFLAGS_OTHER}")
message(WARNING "GLIB_INCLUDE_DIRS: ${GLIB_INCLUDE_DIRS}")
message(WARNING "GLIB_CFLAGS: ${GLIB_CFLAGS}")
message(WARNING "GLIB_CFLAGS_OTHER: ${GLIB_CFLAGS_OTHER}")
pkg_check_modules(DBUS REQUIRED dbus-1)
include_directories(${DBUS_INCLUDE_DIRS})
link_directories(${DBUS_LIBRARIES_DIRS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DBUS_CFLAGS}")
message(WARNING "DBUS_LIBRARIES: ${DBUS_LIBRARIES}")
message(WARNING "DBUS_LIBRARY_DIRS: ${DBUS_LIBRARY_DIRS}")
message(WARNING "DBUS_LDFLAGS: ${DBUS_LDFLAGS}")
message(WARNING "DBUS_LDFLAGS_OTHER: ${DBUS_LDFLAGS_OTHER}")
message(WARNING "DBUS_INCLUDE_DIRS: ${DBUS_INCLUDE_DIRS}")
message(WARNING "DBUS_CFLAGS: ${DBUS_CFLAGS}")
message(WARNING "DBUS_CFLAGS_OTHER: ${DBUS_CFLAGS_OTHER}")
pkg_check_modules(DBUS_GLIB REQUIRED dbus-glib-1)
include_directories(${DBUS_GLIB_INCLUDE_DIRS})
link_directories(${DBUS_GLIB_LIBRARIES_DIRS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DBUS_GLIB_CFLAGS}")
message(WARNING "DBUS_GLIB_LIBRARIES: ${DBUS_GLIB_LIBRARIES}")
message(WARNING "DBUS_GLIB_LIBRARY_DIRS: ${DBUS_GLIB_LIBRARY_DIRS}")
message(WARNING "DBUS_GLIB_LDFLAGS: ${DBUS_GLIB_LDFLAGS}")
message(WARNING "DBUS_GLIB_LDFLAGS_OTHER: ${DBUS_GLIB_LDFLAGS_OTHER}")
message(WARNING "DBUS_GLIB_INCLUDE_DIRS: ${DBUS_GLIB_INCLUDE_DIRS}")
message(WARNING "DBUS_GLIB_CFLAGS: ${DBUS_GLIB_CFLAGS}")
message(WARNING "DBUS_GLIB_CFLAGS_OTHER: ${DBUS_GLIB_CFLAGS_OTHER}")
message(WARNING "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
set(THREADS_PREFER_PTHREAD_FLAG ON)
FIND_PACKAGE(Threads REQUIRED)
# Gets all the header/source files in current directory
file(GLOB SOURCES "*.cpp")
file(GLOB HEADERS "*.h")
file(GLOB GGK_SOURCES "Gobbledegook/src/*.cpp")
file(GLOB GGK_HEADERS "Gobbledegook/src/*.h")
add_executable(
${PROJECT_NAME}
${SOURCES}
${HEADERS}
#${CMAKE_SOURCE_DIR}/Gobbledegook/include/Gobbledegook.h
${GGK_SOURCES}
${GGK_HEADERS}
)
target_include_directories(
${PROJECT_NAME}
PUBLIC ${GLIB_INCLUDE_DIRS}
PUBLIC ${DBUS_INCLUDE_DIRS}
PUBLIC ${DBUS_GLIB_INCLUDE_DIRS}
)
target_link_libraries(
${PROJECT_NAME}
PUBLIC ${GLIB_LIBRARIES}
PUBLIC ${DBUS_LIBRARIES}
PUBLIC ${DBUS_GLIB_LIBRARIES}
Threads::Threads
)
Output from the modified CMake file
ubuntu#tegra-ubuntu:~/visionpro-device-xray/src/user_device_interface/build$ sudo cmake ..
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for module 'glib-2.0'
-- Found glib-2.0, version 2.48.2
CMake Warning at CMakeLists.txt:15 (message):
GLIB_LIBRARIES: glib-2.0
CMake Warning at CMakeLists.txt:16 (message):
GLIB_LIBRARY_DIRS:
CMake Warning at CMakeLists.txt:17 (message):
GLIB_LDFLAGS: -lglib-2.0
CMake Warning at CMakeLists.txt:18 (message):
GLIB_LDFLAGS_OTHER:
CMake Warning at CMakeLists.txt:19 (message):
GLIB_INCLUDE_DIRS:
/usr/include/glib-2.0;/usr/lib/aarch64-linux-gnu/glib-2.0/include
CMake Warning at CMakeLists.txt:20 (message):
GLIB_CFLAGS:
-I/usr/include/glib-2.0;-I/usr/lib/aarch64-linux-gnu/glib-2.0/include
CMake Warning at CMakeLists.txt:21 (message):
GLIB_CFLAGS_OTHER:
-- Checking for module 'dbus-1'
-- Found dbus-1, version 1.10.6
CMake Warning at CMakeLists.txt:28 (message):
DBUS_LIBRARIES: dbus-1
CMake Warning at CMakeLists.txt:29 (message):
DBUS_LIBRARY_DIRS:
CMake Warning at CMakeLists.txt:30 (message):
DBUS_LDFLAGS: -ldbus-1
CMake Warning at CMakeLists.txt:31 (message):
DBUS_LDFLAGS_OTHER:
CMake Warning at CMakeLists.txt:32 (message):
DBUS_INCLUDE_DIRS:
/usr/include/dbus-1.0;/usr/lib/aarch64-linux-gnu/dbus-1.0/include
CMake Warning at CMakeLists.txt:33 (message):
DBUS_CFLAGS:
-I/usr/include/dbus-1.0;-I/usr/lib/aarch64-linux-gnu/dbus-1.0/include
CMake Warning at CMakeLists.txt:34 (message):
DBUS_CFLAGS_OTHER:
-- Checking for module 'dbus-glib-1'
-- Found dbus-glib-1, version 0.106
CMake Warning at CMakeLists.txt:41 (message):
DBUS_GLIB_LIBRARIES: dbus-glib-1;dbus-1;gobject-2.0;glib-2.0
CMake Warning at CMakeLists.txt:42 (message):
DBUS_GLIB_LIBRARY_DIRS:
CMake Warning at CMakeLists.txt:43 (message):
DBUS_GLIB_LDFLAGS: -ldbus-glib-1;-ldbus-1;-lgobject-2.0;-lglib-2.0
CMake Warning at CMakeLists.txt:44 (message):
DBUS_GLIB_LDFLAGS_OTHER:
CMake Warning at CMakeLists.txt:45 (message):
DBUS_GLIB_INCLUDE_DIRS:
/usr/include/dbus-1.0;/usr/lib/aarch64-linux-gnu/dbus-1.0/include;/usr/include/glib-2.0;/usr/lib/aarch64-linux-gnu/glib-2.0/include
CMake Warning at CMakeLists.txt:46 (message):
DBUS_GLIB_CFLAGS:
-I/usr/include/dbus-1.0;-I/usr/lib/aarch64-linux-gnu/dbus-1.0/include;-I/usr/include/glib-2.0;-I/usr/lib/aarch64-linux-gnu/glib-2.0/include
CMake Warning at CMakeLists.txt:47 (message):
DBUS_GLIB_CFLAGS_OTHER:
CMake Warning at CMakeLists.txt:49 (message):
CMAKE_CXX_FLAGS: -std=c++11
-I/usr/include/glib-2.0;-I/usr/lib/aarch64-linux-gnu/glib-2.0/include
-I/usr/include/dbus-1.0;-I/usr/lib/aarch64-linux-gnu/dbus-1.0/include
-I/usr/include/dbus-1.0;-I/usr/lib/aarch64-linux-gnu/dbus-1.0/include;-I/usr/include/glib-2.0;-I/usr/lib/aarch64-linux-gnu/glib-2.0/include
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/visionpro-device-xray/src/user_device_interface/build
I found the issue and it has to do with needing to include gtk+-2.0. I don't know why gtk+-2.0 is used in the library I am linking because its not a graphical program. The CmakeLists.txt should look like this below.
cmake_minimum_required(VERSION 3.2.2)
project(TestBLE)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") #All warning
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra") #Extra warning flags
#####################################################################
# Including Packages
#####################################################################
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB REQUIRED glib-2.0)
include_directories(${GLIB_INCLUDE_DIRS})
pkg_check_modules(GTK2 REQUIRED gtk+-2.0)
include_directories(${GTK2_INCLUDE_DIRS})
set(THREADS_PREFER_PTHREAD_FLAG ON)
FIND_PACKAGE(Threads REQUIRED)
#####################################################################
# Files to add to the executable
#####################################################################
file(GLOB SOURCES "*.cpp")
file(GLOB HEADERS "*.h")
file(GLOB GGK_SOURCES "Gobbledegook/src/*.cpp")
file(GLOB GGK_HEADERS "Gobbledegook/src/*.h")
add_executable(
${PROJECT_NAME}
${SOURCES}
${HEADERS}
#${CMAKE_SOURCE_DIR}/Gobbledegook/include/Gobbledegook.h
${GGK_SOURCES}
${GGK_HEADERS}
)
target_include_directories(
${PROJECT_NAME}
PUBLIC ${GLIB_INCLUDE_DIRS}
)
target_link_libraries(
${PROJECT_NAME}
PUBLIC ${GLIB_LIBRARIES}
PUBLIC ${GTK2_LIBRARIES}
Threads::Threads
)
Hopefully this helps someone else who is trying to incorporate the Gobbledegook Library into their build.

Linking boost library with Boost_USE_STATIC_LIB OFF on Windows

My CMakeFiles.txt looks like this:
cmake_minimum_required ( VERSION 2.6 )
# Set warnings on and enable debugging
SET( CMAKE_C_FLAGS "-Wall -q" )
include(FindBoost)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package( Boost 1.57.0 COMPONENTS system filesystem REQUIRED )
if( Boost_FOUND )
message( STATUS "Boost found!" )
include_directories(${Boost_INCLUDE_DIRS})
add_executable(foo main.cpp)
# Needed for asio
if(WIN32)
target_link_libraries(foo wsock32 ws2_32)
endif()
target_link_libraries(foo ${Boost_LIBRARIES})
endif()
I render the project for Visual Studio 2013 64-bit:
cmake -G "Visual Studio 12 Win64" -DBOOST_LIBRARYDIR=D:\Development\Tools\boost_1_57_0\stage\x64\lib ..\KServer
The output is:
-- The C compiler identification is MSVC 18.0.31101.0
-- The CXX compiler identification is MSVC 18.0.31101.0
-- Check for working C compiler using: Visual Studio 12 2013 Win64
-- Check for working C compiler using: Visual Studio 12 2013 Win64 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 12 2013 Win64
-- Check for working CXX compiler using: Visual Studio 12 2013 Win64 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Boost version: 1.57.0
-- Boost version: 1.57.0
-- Found the following Boost libraries:
-- system
-- filesystem
-- Boost found!
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Development/Private/C++/KServerProject
This is all good and well.
Problem starts here:
When I change my cmake file to use:
set(Boost_USE_STATIC_LIBS OFF)
I then get the following error in Visual Studio when building:
error LNK1104: cannot open file 'libboost_filesystem-vc120-mt-gd-1_57.lib' D:\Development\Private\C++\KServerProject\src\LINK foo
Checking the Property Pages in the studio the library is added as a dependency:
When manually adding the folder D:\Development\Tools\boost_1_57_0\stage\x64\lib to Additional Library Directories it builds fine.
How can I get it to create project using dynamic libs?
I believe you need to add
add_definitions( -DBOOST_ALL_NO_LIB )
See http://www.boost.org/doc/libs/1_57_0/libs/config/doc/html/index.html. I have it set in my CMakeLists.txt and it works for my visual studio builds with boost. As a test, I removed it and got the same error you did.
For what it is worth, here is how I use boost with cmake.
# boost
set(Boost_NO_SYSTEM_PATHS true)
set (Boost_USE_STATIC_LIBS OFF CACHE BOOL "use static libraries from Boost")
set (Boost_USE_MULTITHREADED ON)
find_package(Boost REQUIRED
COMPONENTS
system program_options thread filesystem
date_time chrono timer regex serialization
)
include_directories(${Boost_INCLUDE_DIRS})
link_libraries(${Boost_LIBRARIES})
if (WIN32)
# disable autolinking in boost
add_definitions( -DBOOST_ALL_NO_LIB )
# force all boost libraries to dynamic link (we already disabled
# autolinking, so I don't know why we need this, but we do!)
add_definitions( -DBOOST_ALL_DYN_LINK )
endif()