Compile Cpp file which is using VTK library with CMake - c++

I want to compile cpp source code in which VTK, Eigen, PETSc and dealII libraries are included. source files are located in src directory and header files in ìnclude directory.
The CMakeLists.txtfile is as follows:
cmake_minimum_required(VERSION 3.20.3)
project(ddm_library)
set (CMAKE_CXX_FLAGS "-Wsign-compare -Wno-unused-variable -Wno-unused-parameter -Wdeprecated-copy")
set(VTK_DIR /home/mehdi/myFolder/programming/lib/VTK-9.0.3/build)
# PkgConfig
find_package(PkgConfig)
# PETSc
if (PKG_CONFIG_FOUND)
pkg_check_modules(PETSC PETSc)
endif()
# include PETSC
if (PETSC_FOUND)
list(APPEND COMPILE_OPTIONS ${PETSC_CFLAGS})
include_directories(${PETSC_INCLUDE_DIRS})
set(LINK_FLAGS "${LINK_FLAGS} ${PETSC_LDFLAGS}")
list(APPEND LIBRARIES ${PETSC_LINK_LIBRARIES})
set(CMAKE_REQUIRED_FLAGS ${PETSC_CFLAGS})
set(CMAKE_REQUIRED_INCLUDES "${PETSC_INCLUDE_DIRS}")
endif()
# include Eigen
find_package (Eigen3 3.3 REQUIRED NO_MODULE)
# VTK library
find_package(VTK COMPONENTS
vtkCommonColor
vtkCommonCore
vtkCommonDataModel
vtkInteractionStyle
vtkRenderingContextOpenGL2
vtkRenderingCore
vtkRenderingFreeType
vtkRenderingGL2PSOpenGL2
vtkRenderingOpenGL2
vtkCommonCore
vtkCommonDataModel
vtkIOXML
QUIET
)
if (NOT VTK_FOUND)
message("Skipping StructuredGrid: ${VTK_NOT_FOUND_MESSAGE}")
return ()
endif()
message (STATUS "VTK_VERSION: ${VTK_VERSION}")
# dealII
FIND_PACKAGE(deal.II 9.3.0 QUIET
HINTS ${deal.II_DIR} ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
)
IF(NOT ${deal.II_FOUND})
MESSAGE(FATAL_ERROR "\n"
"*** Could not locate a (sufficiently recent) version of deal.II. ***\n\n"
"You may want to either pass a flag -DDEAL_II_DIR=/path/to/deal.II to cmake\n"
"or set an environment variable \"DEAL_II_DIR\" that contains this path."
)
ENDIF()
DEAL_II_INITIALIZE_CACHED_VARIABLES()
if (VTK_VERSION VERSION_LESS "8.90.0")
# old system
INCLUDE_DIRECTORIES(include ${VTK_USE_FILE} ${VTK_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIR})
file (GLOB LIB "src/*.cc")
ADD_LIBRARY(lib ${LIB})
vtk_module_autoinit(
TARGETS lib
MODULES ${VTK_LIBRARIES}
)
DEAL_II_SETUP_TARGET(lib)
add_executable(${PROJECT_NAME} MACOSX_BUNDLE "test/main.cc")
DEAL_II_SETUP_TARGET(${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME} PRIVATE lib Eigen3::Eigen ${VTK_LIBRARIES})
else ()
# include all components
INCLUDE_DIRECTORIES(include ${VTK_USE_FILE} ${VTK_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIR})
file (GLOB LIB "src/*.cc")
ADD_LIBRARY(lib ${LIB})
vtk_module_autoinit(
TARGETS lib
MODULES ${VTK_LIBRARIES}
)
DEAL_II_SETUP_TARGET(lib)
add_executable(${PROJECT_NAME} MACOSX_BUNDLE "test/main.cc")
DEAL_II_SETUP_TARGET(${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME} PRIVATE lib Eigen3::Eigen ${VTK_LIBRARIES})
# vtk_module_autoinit is needed
vtk_module_autoinit(
TARGETS ${PROJECT_NAME}
MODULES ${VTK_LIBRARIES}
)
endif ()
running cmd like
$ cmake -DCMAKE_BUILD_TYPE=Debug ..
-- The C compiler identification is GNU 11.1.0
-- The CXX compiler identification is GNU 11.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.7.3")
-- Checking for module 'PETSc'
-- Found PETSc, version 3.15.0
-- VTK_VERSION: 9.0.3
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mehdi/myFolder/programming/domain_decomposition/build
which finds all the packages. Then running the cmd
$ make
cc1plus: warning: /home/mehdi/myFolder/programming/lib/VTK-9.0.3/build/lib/cmake/vtk-9.0/vtk-use-file-deprecated.cmake: not a directory
In file included from /home/mehdi/myFolder/programming/domain_decomposition/src/post_processing.cc:2:
/home/mehdi/myFolder/programming/domain_decomposition/include/post_processing.hpp:14:10: fatal error: vtkActor.h: No such file or directory
14 | #include <vtkActor.h>
| ^~~~~~~~~~~~
I can not understand why I got such a error.

I modified the CMakeLists.txtby removing PRIVATEfrom target_link_librariesand add target_link_librariesfor lib, and the problem solved. The new CMakeLists.txt is look like this:
cmake_minimum_required(VERSION 3.20.3)
project(ddm_library)
set (CMAKE_CXX_FLAGS "-Wsign-compare -Wno-unused-variable -Wno-unused-parameter -Wdeprecated-copy")
set(VTK_DIR /home/mehdi/myFolder/programming/lib/VTK-9.0.3/build)
# PkgConfig
find_package(PkgConfig)
# PETSc
if (PKG_CONFIG_FOUND)
pkg_check_modules(PETSC PETSc)
endif()
# include PETSC
if (PETSC_FOUND)
list(APPEND COMPILE_OPTIONS ${PETSC_CFLAGS})
include_directories(${PETSC_INCLUDE_DIRS})
set(LINK_FLAGS "${LINK_FLAGS} ${PETSC_LDFLAGS}")
list(APPEND LIBRARIES ${PETSC_LINK_LIBRARIES})
set(CMAKE_REQUIRED_FLAGS ${PETSC_CFLAGS})
set(CMAKE_REQUIRED_INCLUDES "${PETSC_INCLUDE_DIRS}")
endif()
# include Eigen
find_package (Eigen3 3.3 REQUIRED NO_MODULE)
# VTK library
find_package(VTK COMPONENTS
vtkCommonColor
vtkCommonCore
vtkCommonDataModel
vtkInteractionStyle
vtkRenderingContextOpenGL2
vtkRenderingCore
vtkRenderingFreeType
vtkRenderingGL2PSOpenGL2
vtkRenderingOpenGL2
vtkCommonCore
vtkCommonDataModel
vtkIOXML
QUIET
)
if (NOT VTK_FOUND)
message("Skipping StructuredGrid: ${VTK_NOT_FOUND_MESSAGE}")
return ()
endif()
message (STATUS "VTK_VERSION: ${VTK_VERSION}")
# dealII
FIND_PACKAGE(deal.II 9.3.0 QUIET
HINTS ${deal.II_DIR} ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
)
IF(NOT ${deal.II_FOUND})
MESSAGE(FATAL_ERROR "\n"
"*** Could not locate a (sufficiently recent) version of deal.II. ***\n\n"
"You may want to either pass a flag -DDEAL_II_DIR=/path/to/deal.II to cmake\n"
"or set an environment variable \"DEAL_II_DIR\" that contains this path."
)
ENDIF()
DEAL_II_INITIALIZE_CACHED_VARIABLES()
#INCLUDE_DIRECTORIES(SYSTEM ${VTK_INCLUDE_DIRS})
if (VTK_VERSION VERSION_LESS "8.90.0")
# old system
INCLUDE_DIRECTORIES(include ${VTK_USE_FILE} ${VTK_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIR})
FILE (GLOB LIB "src/*.cc")
ADD_LIBRARY(lib OBJECT ${LIB})
vtk_module_autoinit(
TARGETS lib
MODULES ${VTK_LIBRARIES}
)
TARGET_LINK_LIBRARIES(lib Eigen3::Eigen ${VTK_LIBRARIES})
DEAL_II_SETUP_TARGET(lib)
add_executable(${PROJECT_NAME} MACOSX_BUNDLE "test/main.cc")
DEAL_II_SETUP_TARGET(${PROJECT_NAME})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} lib Eigen3::Eigen ${VTK_LIBRARIES})
else ()
# include all components
INCLUDE_DIRECTORIES(include ${VTK_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIR})
FILE (GLOB LIB "src/*.cc")
ADD_LIBRARY(lib OBJECT ${LIB})
vtk_module_autoinit(
TARGETS lib
MODULES ${VTK_LIBRARIES}
)
TARGET_LINK_LIBRARIES(lib Eigen3::Eigen ${VTK_LIBRARIES})
DEAL_II_SETUP_TARGET(lib)
add_executable(${PROJECT_NAME} MACOSX_BUNDLE "test/main.cc")
DEAL_II_SETUP_TARGET(${PROJECT_NAME})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} lib Eigen3::Eigen ${VTK_LIBRARIES})
# vtk_module_autoinit is needed
vtk_module_autoinit(
TARGETS ${PROJECT_NAME}
MODULES ${VTK_LIBRARIES}
)
endif ()

Related

mingw-g++ can't find include directory

I'm trying to compile my program for Windows, on Linux, so I installed the w64-mingw32 compiler via the Debian package manager. I made a separate cmakelists file where I chose x86_64-w64-mingw32-g++ as the compiler. When I try to run my build script, I get errors where it can't find the libraries that I use in my project. This is my cmake file:
cmake_minimum_required (VERSION 3.5)
if (POLICY CMP0072)
cmake_policy(SET CMP0072 NEW)
else (NOT POLICY CMP0072)
message(STATUS "Could not use CMP0072 policy")
endif(POLICY CMP0072)
project(opengl-test LANGUAGES CXX)
set(CMAKE_CXX_COMPILER "/usr/bin/x86_64-w64-mingw32-g++")
set(CMAKE_C_COMPILER "/usr/bin/x86_64-w64-mingw32-gcc")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(GNUInstallDirs)
set(CMAKE_FIND_ROOT_PATH "/usr/x86_64-w64-mingw32")
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set (source_dir "${PROJECT_SOURCE_DIR}/src/")
set (base_dir "${source_dir}/base/")
set (IMGUI_DIR "/usr/include/imgui")
set(GCC_COVERAGE_LINK_FLAGS "")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
file(GLOB source_files "${source_dir}/*.cpp")
file(GLOB_RECURSE base_files "${base_dir}/*.cpp")
file(GLOB imgui_files "${IMGUI_DIR}/*.cpp")
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
add_executable(${PROJECT_NAME} ${source_files} ${imgui_files} ${base_files})
#target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
message(STATUS ${OPENGL_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PUBLIC ${GLFW_LIBRARIES} ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES})
A lot of the code in the cmakelists file doesn't do anything because I was trying to make it work but nothing was working. I left it in so you can see what I've tried and doesn't work.
I can run this and it compiles, but I get a linker error.
CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.
-- /usr/lib/x86_64-linux-gnu/libOpenGL.so/usr/lib/x86_64-linux-gnu/libGLX.so/usr/lib/x86_64-linux-gnu/libGLU.so
-- Configuring done
CMake Warning at CMakeLists.txt:38 (add_executable):
Cannot generate a safe runtime search path for target opengl-test because
files in some directories may conflict with libraries in implicit
directories:
runtime library [libGLEW.so.2.1] in /usr/lib64 may be hidden by files in:
/usr/lib/x86_64-linux-gnu
Some of these libraries may not be found correctly.
-- Generating done
-- Build files have been written to: /home/user/Documents/CPP-Stuff/Scrap-Framework
[29/29] Linking CXX executable opengl-test
FAILED: opengl-test
: && /usr/bin/x86_64-w64-mingw32-g++ -g CMakeFiles/opengl-test.dir/src/main.cpp.o CMakeFiles/opengl-test.dir/usr/include/imgui/imgui.cpp.o CMakeFiles/opengl-test.dir/usr/include/imgui/imgui_demo.cpp.o CMakeFiles/opengl-test.dir/usr/include/imgui/imgui_draw.cpp.o CMakeFiles/opengl-test.dir/usr/include/imgui/imgui_impl_glfw.cpp.o CMakeFiles/opengl-test.dir/usr/include/imgui/imgui_impl_opengl3.cpp.o CMakeFiles/opengl-test.dir/usr/include/imgui/imgui_tables.cpp.o CMakeFiles/opengl-test.dir/usr/include/imgui/imgui_widgets.cpp.o CMakeFiles/opengl-test.dir/src/base/Application/Application.cpp.o CMakeFiles/opengl-test.dir/src/base/Application/Window.cpp.o CMakeFiles/opengl-test.dir/src/base/GL/Cubemap.cpp.o CMakeFiles/opengl-test.dir/src/base/GL/Texture.cpp.o CMakeFiles/opengl-test.dir/src/base/GL/UniformBuffer.cpp.o CMakeFiles/opengl-test.dir/src/base/GL/VertexBuffer.cpp.o CMakeFiles/opengl-test.dir/src/base/Input/Input.cpp.o CMakeFiles/opengl-test.dir/src/base/Model/Material.cpp.o CMakeFiles/opengl-test.dir/src/base/Model/Mesh.cpp.o CMakeFiles/opengl-test.dir/src/base/Model/Model.cpp.o CMakeFiles/opengl-test.dir/src/base/Model/ModelLoader.cpp.o CMakeFiles/opengl-test.dir/src/base/Renderer/FPSCamera.cpp.o CMakeFiles/opengl-test.dir/src/base/Renderer/MaterialManager.cpp.o CMakeFiles/opengl-test.dir/src/base/Renderer/Renderbuffer.cpp.o CMakeFiles/opengl-test.dir/src/base/Renderer/Renderer.cpp.o CMakeFiles/opengl-test.dir/src/base/Scene/Lights.cpp.o CMakeFiles/opengl-test.dir/src/base/Scene/Scene.cpp.o CMakeFiles/opengl-test.dir/src/base/Scene/Skybox.cpp.o CMakeFiles/opengl-test.dir/src/base/Shader/Shader.cpp.o CMakeFiles/opengl-test.dir/src/base/Shader/ShaderManager.cpp.o -o opengl-test -Wl,-rpath,/usr/lib/x86_64-linux-gnu -lglfw /usr/lib/x86_64-linux-gnu/libOpenGL.so /usr/lib/x86_64-linux-gnu/libGLX.so /usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib64/libGLEW.so && :
/usr/bin/x86_64-w64-mingw32-ld: cannot find -lglfw
/usr/bin/x86_64-w64-mingw32-ld: /usr/lib/x86_64-linux-gnu/libOpenGL.so: error adding symbols: file in wrong format
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
The include files are located in /usr/include/, but I also put them in /usr/x86_64-w64-mingw32/include/.
Does anyone know how I can fix this, or a better way to compile for Windows on Linux?
You need to build the libraries you're using for Windows, or find prebuilt ones, e.g. in MSYS2 repositories. You also need to point CMake to those libraries.
I've made Quasi-MSYS2 to automate both.
Example usage:
# Install Clang, LLD, Wine. Then:
git clone https://github.com/holyblackcat/quasi-msys2
cd quasi-msys2/
make install _gcc _glfw _glew
env/shell.sh
# Build
cd your/project/location
mkdir build
cd build
cmake ..
make
# Run with Wine
./a.exe
Here is CMakeLists.txt I've used. I removed the cross-compilation stuff (which is handled automatically).
cmake_minimum_required (VERSION 3.5)
if (POLICY CMP0072)
cmake_policy(SET CMP0072 NEW)
else (NOT POLICY CMP0072)
message(STATUS "Could not use CMP0072 policy")
endif(POLICY CMP0072)
project(opengl-test LANGUAGES CXX)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
add_executable(a 1.cpp)
message(STATUS ${OPENGL_LIBRARIES})
target_link_libraries(a PUBLIC ${GLFW_LIBRARIES} ${OPENGL_LIBRARIES} GLEW::GLEW)
I also put them in /usr/x86_64-w64-mingw32/include/
You shouldn't modify system include directories manually. Leave them to your package manager.

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

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.

Can't make cgal and hdf5 work together

I am using these steps (line 42 in the 2nd sourcecode place). However, I reading/writing to files with .h5 extension, where the code needs surely this flag: -lhdf5.
In order to compile the functions for hdf5, I would do something like this:
g++ -std=c++0x main.cpp -lhdf5
Notice that the flag must be placed at the end of the compilation command, as stated in this answer.
I updated my question, due to a comment.
So, I modified the CMakeLists.txt and what I changed was this part:
add_definitions(${CMAKE_CXX_FLAGS} "-std=c++0x")
set(CMAKE_EXE_LINKER_FLAGS "-lhdf5 -lhdf5_hl -lhdf5_cpp")
However, when I execute make, it seems that hdf5 is not found.
EDIT
With Marc's suggestion, I got:
Linking CXX executable exe
/usr/bin/cmake -E cmake_link_script CMakeFiles/exe.dir/link.txt --verbose=1
/usr/bin/c++ -frounding-math -O3 -DNDEBUG -lhdf5 -lhdf5_hl -lhdf5_cpp CMakeFiles/exe.dir/match.cpp.o -o exe -rdynamic -L/home/samaras/code/CGAL-4.3/lib -L/usr/local/lib -lmpfr -lgmp /home/samaras/code/CGAL-4.3/lib/libCGAL.so -lboost_thread-mt -lpthread /usr/local/lib/libboost_system.so /home/samaras/code/CGAL-4.3/lib/libCGAL.so -lboost_thread-mt -lpthread /usr/local/lib/libboost_system.so -Wl,-rpath,/home/samaras/code/CGAL-4.3/lib:/usr/local/lib
and here is the problem, I think (see the answer I linked too). The linker flag of hdf5 is NOT at the end.
How to put it at the end? Maybe I am using the wrong set()?
EDIT - solution
Here is the working CMakeLists.txt:
# Created by the script cgal_create_cmake_script_with_options
# This is the CMake script for compiling a set of CGAL applications.
project( exe )
cmake_minimum_required(VERSION 2.6.2)
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6)
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3)
cmake_policy(VERSION 2.8.4)
else()
cmake_policy(VERSION 2.6)
endif()
endif()
set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true )
if ( COMMAND cmake_policy )
cmake_policy( SET CMP0003 NEW )
endif()
# CGAL and its components
add_definitions(${CMAKE_CXX_FLAGS} "-std=c++0x")
find_package( CGAL QUIET COMPONENTS )
if ( NOT CGAL_FOUND )
message(STATUS "This project requires the CGAL library, and will not be compiled.")
return()
endif()
# include helper file
include( ${CGAL_USE_FILE} )
find_package (CGAL)
include (${CGAL_USE_FILE})
add_definitions (${CGAL_CXX_FLAGS_INIT})
include_directories (${CGAL_INCLUDE_DIRS})
set (libraries ${libraries} ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES})
set (CMAKE_EXE_LINKER_FLAGS "-dynamic ${CMAKE_EXE_LINKER_FLAGS}")
find_package (HDF5 QUIET COMPONENTS CXX)
if (HDF5_FOUND)
include_directories (SYSTEM ${HDF5_CXX_INCLUDE_DIR})
set (HDF5_libraries ${HDF5_hdf5_LIBRARY} ${HDF5_hdf5_cpp_LIBRARY})
set (HDF5_libraries hdf5 hdf5_cpp)
endif (HDF5_FOUND)
# Boost and its components
find_package( Boost REQUIRED )
if ( NOT Boost_FOUND )
message(STATUS "This project requires the Boost library, and will not be compiled.")
return()
endif()
# include for local directory
# include for local package
# Creating entries for target: exe
# ############################
add_executable( exe match.cpp )
add_to_cached_list( CGAL_EXECUTABLE_TARGETS exe )
# Link the executable to CGAL and third-party libraries
target_link_libraries(exe ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} ${libraries} ${HDF5_libraries})
I use CGAL and HDF5 together. Here's the relevant bit from my CMakeLists.txt:
find_package (HDF5 QUIET COMPONENTS CXX)
if (HDF5_FOUND)
include_directories (SYSTEM ${HDF5_CXX_INCLUDE_DIR})
add_library (hdf5 STATIC IMPORTED)
set_target_properties (hdf5 PROPERTIES IMPORTED_LOCATION ${HDF5_hdf5_LIBRARY})
add_library (hdf5_cpp STATIC IMPORTED)
set_target_properties (hdf5_cpp PROPERTIES IMPORTED_LOCATION ${HDF5_hdf5_cpp_LIBRARY})
set (HDF5_libraries hdf5 hdf5_cpp)
add_executable (exe match.cpp)
target_link_libraries (exe ${libraries} ${HDF5_libraries})
endif (HDF5_FOUND)
Earlier in CMakeLists.txt, there is:
find_package (CGAL)
include (${CGAL_USE_FILE})
add_definitions (${CGAL_CXX_FLAGS_INIT})
include_directories (${CGAL_INCLUDE_DIRS})
set (libraries ${libraries} ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES})
set (CMAKE_EXE_LINKER_FLAGS "-dynamic ${CMAKE_EXE_LINKER_FLAGS}")