I am trying to install AirSim/Unity on MacOS Catalina. When I run Unity/build.sh I get a fatal error:
In file included from /Users/nfirbas/Documents/AirSim/Unity/AirLibWrapper/AirsimWrapper/Source/Logger.cpp:3:
/Users/nfirbas/Documents/AirSim/Unity/AirLibWrapper/AirsimWrapper/Source/Logger.h:6:11: fatal error: 'boost/filesystem.hpp' file not found
#include <boost/filesystem.hpp>
^~~~~~~~~~~~~~~~~~~~~~
1 warning and 1 error generated.
make[2]: *** [CMakeFiles/AirsimWrapper.dir/Source/Logger.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
I have installed boost with brew. It's my first time working with brew so I assume that I need to edit my CMakeList.txt. I tried changing it myself but I didn't get it working.
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.5.0)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MACOSX TRUE)
endif()
find_path(AIRSIM_ROOT NAMES AirSim.sln PATHS ".." "../.." "../../.." "../../../.." "../../../../.." "../../../../../..")
message(AirSim Root directory: ${AIRSIM_ROOT})
LIST(APPEND CMAKE_MODULE_PATH "${AIRSIM_ROOT}/cmake/cmake-modules")
LIST(APPEND CMAKE_MODULE_PATH "${RPC_SOURCE_DIR}/cmake")
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
INCLUDE("${AIRSIM_ROOT}/cmake/cmake-modules/CommonSetup.cmake")
INCLUDE("${CMAKE_CURRENT_SOURCE_DIR}/cmake/rpc-setup.cmake")
INCLUDE("${CMAKE_CURRENT_SOURCE_DIR}/cmake/mav-setup.cmake")
INCLUDE("${CMAKE_CURRENT_SOURCE_DIR}/cmake/airlib-setup.cmake")
INCLUDE("${CMAKE_CURRENT_SOURCE_DIR}/cmake/airsimwrapper-setup.cmake")
IncludeEigen()
project(AirsimWrapper VERSION 0)
# RPC includes & source files
BuildRpc()
# MavLink source files
BuildMavLink()
#AirLib source files
BuildAirlib()
#AirsimWrapper source files
BuildAirsimWrapper()
###################### Link source files to library ######################################
if (${APPLE})
add_library(
${PROJECT_NAME} MODULE
${RPC_LIBRARY_SOURCE_FILES}
${MAVLINK_LIBRARY_SOURCE_FILES}
${AIRLIB_LIBRARY_SOURCE_FILES}
${AIRSIMWRAPPER_LIBRARY_SOURCE_FILES}
)
set_target_properties(${PROJECT_NAME} PROPERTIES BUNDLE TRUE)
else ()
add_library(
${PROJECT_NAME} SHARED
${RPC_LIBRARY_SOURCE_FILES}
${MAVLINK_LIBRARY_SOURCE_FILES}
${AIRLIB_LIBRARY_SOURCE_FILES}
${AIRSIMWRAPPER_LIBRARY_SOURCE_FILES}
)
endif ()
target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT} -lstdc++ -lpthread -lboost_filesystem)
##################### Build Options #############################3
# Rpc
RpcCheckMSVN()
RpcCmakePkg()
RpcMSVNConfig()
You have told your library target to link against boost_filesystem, but you did not convey in your CMake where to find the Boost header files.
The idiomatic way to find Boost using CMake is to use the configuration files that now ship with Boost (e.g. BoostConfig.cmake), as of Boost version 1.70 and greater. You can make use of these by calling find_package(Boost ...), then linking with the imported target Boost::filesystem:
# Tell CMake to locate Boost on your machine, specifically
# looking for the filesystem library.
find_package(Boost REQUIRED COMPONENTS filesystem)
...
# Link the Boost::filesystem target, which includes the Boost headers.
target_link_libraries(${PROJECT_NAME} PUBLIC
${CMAKE_THREAD_LIBS_INIT}
-lstdc++
-lpthread
Boost::filesystem
)
This will pull in the Boost headers as well, so you don't need an explicit call to target_include_directories() to specify where the Boost headers are.
Note: To ensure the headers are installed on your system, you may need to install boost-devel, in addition to your boost installation.
Related
I'm trying to compile freetype2 from source and link it in my own project, but I'm running into a CMake error:
CMake Error: install(EXPORT "freetype-targets" ...) includes target "freetype" which requires target "zlib" that is not in any export set.
Presumably, this means that zlib is not recognizable to the freetype2 target.
I am compiling and using zlib in this project for other things (libpng, specifically), so am I correct in assuming that I simply need to somehow make my compiled zlib available to freetype2? How would I go about doing this?
Here is the entirety of my CMakeLists.txt:
cmake_minimum_required(VERSION 3.17)
project(zgl)
set(CMAKE_CXX_STANDARD 17)
set(SKIP_INSTALL_EXPORT TRUE)
# If this is built standalone, and not part of an embedded project, define the build directory.
string(COMPARE EQUAL ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} IS_ROOT_PROJECT)
if(IS_ROOT_PROJECT)
if(NOT DEFINED DEPS_INSTALL_PREFIX)
set(DEPS_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/build" CACHE STRING "Installation Prefix" FORCE)
endif()
get_property(CMAKE_INSTALL_PREFIX_DOCS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY CMAKE_INSTALL_PREFIX FULL_DOCS)
set(CMAKE_INSTALL_PREFIX ${DEPS_INSTALL_PREFIX} CACHE STRING "${CMAKE_INSTALL_PREFIX_DOCS}" FORCE)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin)
set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin)
endif()
set(THIRD_PARTY_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/third-party)
set(ZLIB_DIRECTORY ${THIRD_PARTY_DIRECTORY}/zlib)
add_subdirectory(${ZLIB_DIRECTORY})
# Explicitly set the ZLIB_BUILD_DIRECTORY for libpng (?)
get_directory_property(ZLIB_BUILD_DIRECTORY DIRECTORY ${ZLIB_DIRECTORY} DEFINITION CMAKE_CURRENT_BINARY_DIR)
option(PNG_LINK_ZLIB_STATIC "Use a static zlib library for libpng builds" OFF)
get_directory_property(zlib DIRECTORY ${ZLIB_DIRECTORY} DEFINITION zlib)
get_directory_property(zlibstatic DIRECTORY ${ZLIB_DIRECTORY} DEFINITION zlibstatic)
if (PNG_LINK_ZLIB_STATIC)
set(ZLIB_LIBRARY zlibstatic)
else()
set(ZLIB_LIBRARY zlib)
endif()
set(ZLIB_INCLUDE_DIR ${ZLIB_DIRECTORY})
set(LIBPNG_DIRECTORY "${THIRD_PARTY_DIRECTORY}/libpng")
if (WIN32)
file(TO_NATIVE_PATH ${LIBPNG_DIRECTORY}/scripts/pnglibconf.h.prebuilt PNGLIBCONF_PATH_SRC)
file(TO_NATIVE_PATH ${LIBPNG_DIRECTORY}/pnglibconf.h PNGLIBCONF_PATH_DST)
execute_process(COMMAND cmd /c copy ${PNGLIBCONF_PATH_SRC} ${PNGLIBCONF_PATH_DST})
endif(WIN32)
include_directories(${ZLIB_DIRECTORY} ${ZLIB_BUILD_DIRECTORY} ${LIBPNG_DIRECTORY} ${LIBPNG_BUILD_DIRECTORY})
add_subdirectory(${LIBPNG_DIRECTORY})
get_directory_property(LIBPNG_BUILD_DIRECTORY DIRECTORY ${LIBPNG_DIRECTORY} DEFINITION CMAKE_CURRENT_BINARY_DIR)
get_directory_property(LIBPNG_STATIC DIRECTORY ${LIBPNG_DIRECTORY} DEFINITION PNG_LIB_NAME_STATIC)
get_directory_property(LIBPNG_SHARED DIRECTORY ${LIBPNG_DIRECTORY} DEFINITION PNG_LIB_NAME)
add_executable(zgl src/main.cpp src/resources/images/Image.cpp src/Game.cpp src/Game.h src/platform/Platform.cpp src/platform/Platform.h src/platform/Window.cpp src/platform/Window.h src/components/GameComponent.cpp src/components/GameComponent.h src/input/InputEvent.h src/input/Joystick.cpp src/input/Joystick.h src/utilities/StringUtilities.cpp src/utilities/StringUtilities.h src/input/InputEvent.cpp src/Actor.cpp src/Actor.h src/Scene.cpp src/Scene.h src/math/Range.h src/components/CameraComponent.cpp src/components/CameraComponent.h src/components/GameComponentCollection.h src/FreeCamera.cpp src/FreeCamera.h src/input/InputManager.cpp src/input/InputManager.h src/math/Rectangle.h src/input/InputSubscription.cpp src/input/InputSubscription.h src/Application.cpp src/Application.h src/math/Interpolation.h src/graphics/Texture.cpp src/graphics/Texture.h src/graphics/Gpu.cpp src/graphics/Gpu.h src/graphics/ColorType.h src/graphics/TextureFormat.h src/input/InputSubscriber.cpp src/input/InputSubscriber.h src/graphics/ColorType.cpp src/resources/images/formats/ImageFormatPng.cpp src/resources/images/formats/ImageFormatPng.h src/resources/ResourceManager.cpp src/resources/ResourceManager.h src/resources/images/formats/ImageFormat.cpp src/resources/images/formats/ImageFormat.h src/resources/Resource.cpp src/resources/Resource.h src/graphics/FrameBuffer.cpp src/graphics/FrameBuffer.h src/graphics/GpuTypes.h src/graphics/GpuProgram.cpp src/graphics/GpuProgram.h src/input/joysticks/XboxController.h src/input/InputAction.cpp src/input/InputAction.h src/utilities/FlagMacros.h src/input/Pointer.cpp src/input/Pointer.h src/input/Keyboard.cpp src/input/Keyboard.h src/input/KeyboardKey.cpp src/input/KeyboardKey.h src/components/FreeCameraControllerComponent.cpp src/components/FreeCameraControllerComponent.h src/components/GameComponentRegistry.cpp src/components/GameComponentRegistry.h src/platform/Cursor.cpp src/platform/Cursor.h src/graphics/GpuBuffer.cpp src/graphics/GpuBuffer.h src/graphics/GpuIndexBuffer.h src/components/MeshComponent.cpp src/components/MeshComponent.h src/graphics/GpuVertexBuffer.h src/resources/mesh/Mesh.cpp src/resources/mesh/Mesh.h src/ActorDefinition.cpp src/ActorDefinition.h src/graphics/CameraParameters.h)
# Compiling GLEW requires CYGWIN to be installed on Windows!
#glew
set(GLEW_DIRECTORY "${THIRD_PARTY_DIRECTORY}/glew-cmake")
message("${GLEW_DIRECTORY}")
add_subdirectory(${GLEW_DIRECTORY})
include_directories(${GLEW_DIRECTORY}/include)
target_link_libraries(zgl libglew_static)
#glfw
set(GLFW_DIRECTORY "${THIRD_PARTY_DIRECTORY}/glfw")
add_subdirectory(${GLFW_DIRECTORY})
include_directories(${GLFW_DIRECTORY}/include)
#opengl
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIRS})
#freetype
set(FREETYPE_DIRECTORY "${THIRD_PARTY_DIRECTORY}/freetype2")
add_subdirectory(${FREETYPE_DIRECTORY})
include_directories(${FREETYPE_DIRECTORY}/include)
#glm
set(GLM_DIRECTORY "${THIRD_PARTY_DIRECTORY}/glm")
include_directories(${GLM_DIRECTORY})
#yaml-cpp
set(YAML_DIRECTORY "${THIRD_PARTY_DIRECTORY}/yaml-cpp")
add_subdirectory(${YAML_DIRECTORY})
set(YAML_LIBRARIES yaml-cpp)
include_directories(${YAML_DIRECTORY}/include)
#magic_enum
set(MAGIC_ENUM_DIRECTORY "${THIRD_PARTY_DIRECTORY}/magic_enum")
include_directories(${MAGIC_ENUM_DIRECTORY}/include)
#zgl
set(ZGL_SRC_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src")
include_directories(${ZGL_SRC_DIRECTORY})
target_link_libraries(zgl ${OPENGL_LIBRARIES})
target_link_libraries(zgl ${ZLIB_LIBRARY})
target_link_libraries(zgl ${FREETYPE_LIBRARY})
target_link_libraries(zgl ${LIBPNG_STATIC})
target_link_libraries(zgl glfw ${GLFW_LIBRARIES})
target_link_libraries(zgl ${BULLET3_LIRRARIES})
target_link_libraries(zgl ${YAML_LIBRARIES})
target_include_directories(zgl PUBLIC ${ZLIB_DIRECTORY})
target_include_directories(zgl PUBLIC ${LIBPNG_DIRECTORY})
The error message
CMake Error: install(EXPORT "freetype-targets" ...) includes target "freetype" which requires target "zlib" that is not in any export set.
refers to lines
install(
TARGETS freetype
EXPORT freetype-targets
<...>)
in the freetype2's CMakeLists.txt.
These lines mark freetype target for installation and add this target to the export set, so that installation could be found via find_package.
The target freetype is linked with the target zlib because you specify
set(ZLIB_LIBRARY zlib)
And here the problem CMake points to:
while zlib target is installed, it is part of none export sets.
Because of that CMake doesn't know how to translate linkage of freetype with zlib after they are installed, so CMake is unable to generate config file for freetype installation.
For overcome the error, you may tell CMake to link freetype with ALIAS library instead:
add_library(ZLIB::ZLIB ALIAS zlib)
set(ZLIB_LIBRARY ZLIB::ZLIB)
CMake knows that ALIAS targets are never installed, and won't emit an error.
Note, that while with ALIAS target the error will be gone, find_package still won't work for the installed freetype2. But otherwise the installation will be correct and usable.
I try to make kenlm binaries usable on Android. Kenlm is written in c++ and uses cmake, so I tried to do a toolchain file to crosscompile with cmake.
My toolchain file looks like that :
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 26)
set(CMAKE_ANDROID_ARCH_ABI arm64-v8a)
set(CMAKE_ANDROID_NDK "/home/marie/Android/Sdk/ndk/16.1.4479499")
set(BZIP2_LIBRARIES "/usr/lib/x86_64-linux-gnu")
set(LIBLZMA_LIBRARY "/usr/lib/x86_64-linux-gnu/liblzma.so")
set(LIBLZMA_LIBRARIES "/lib/x86_64-linux-gnu")
set(LIBLZMA_HAS_AUTO_DECODER TRUE)
set(LIBLZMA_HAS_EASY_ENCODER TRUE)
set(LIBLZMA_HAS_LZMA_PRESET TRUE)
set(ZLIB_LIBRARIES "/home/marie/Android/Sdk/ndk/16.1.4479499/platforms/android-26/arch-arm64/usr/lib")
and the CMakeLists.txt from kenlm
cmake_minimum_required(VERSION 2.6)
# Define a single cmake project
project(kenlm)
option(FORCE_STATIC "Build static executables" OFF)
if (FORCE_STATIC)
#presumably overkill, is there a better way?
#http://cmake.3232098.n2.nabble.com/Howto-compile-static-executable-td5580269.html
set(Boost_USE_STATIC_LIBS ON)
set_property(GLOBAL PROPERTY LINK_SEARCH_START_STATIC ON)
set_property(GLOBAL PROPERTY LINK_SEARCH_END_STATIC ON)
set(BUILD_SHARED_LIBRARIES OFF)
if (MSVC)
set(flag_vars
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
foreach(flag_var ${flag_vars})
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
else (MSVC)
if (NOT CMAKE_C_COMPILER_ID MATCHES ".*Clang")
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
endif ()
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
endif ()
#Annoyingly the exectuables say "File not found" unless these are set
set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS)
set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS)
set(CMAKE_SHARED_LIBRARY_C_FLAGS)
set(CMAKE_SHARED_LIBRARY_CXX_FLAGS)
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
endif ()
# Compile all executables into bin/
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
# Compile all libraries into lib/
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
option(COMPILE_TESTS "Compile tests" OFF)
if (COMPILE_TESTS)
# Tell cmake that we want unit tests to be compiled
include(CTest)
enable_testing()
endif()
# Add our CMake helper functions
include(cmake/KenLMFunctions.cmake)
if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} /w34716")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /w34716")
endif()
# And our helper modules
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
# We need boost
find_package(Boost 1.41.0 REQUIRED COMPONENTS
program_options
system
thread
unit_test_framework
)
# Define where include files live
include_directories(
${PROJECT_SOURCE_DIR}
${Boost_INCLUDE_DIRS}
)
# Process subdirectories
add_subdirectory(util)
add_subdirectory(lm)
When i try to
cmake -DCMAKE_TOOLCHAIN_FILE="./cmake_toolchain.cmake" ..
I get that
...
Unable to find the requested Boost libraries.
Boost version: 1.65.1
Boost include path: /usr/include
Could not find the following Boost libraries:
boost_program_options
boost_system
boost_thread
boost_unit_test_framework
...
So i tried to add the boost dir in the toolchain file :
set(BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu")
And it workd for the boost libraries but another error pops
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- program_options
-- system
-- thread
-- unit_test_framework
-- chrono
-- date_time
-- atomic
...
-- Configuring done
WARNING: Target "kenlm_util" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "probing_hash_table_benchmark" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "query" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "fragment" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "kenlm" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "build_binary" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "kenlm_benchmark" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "lmplz" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "count_ngrams" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "kenlm_builder" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "filter" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "phrase_table_vocab" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "streaming_example" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "interpolate" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
-- Generating done
I've been trying many things to make it work like set(LINK_DIRECTORIES), set(CMAKE_INCLUDE_PATH), set(Boost_LIBRARY_DIRS) (to add multiple boost dirs), set(KENLM_ROOT_DIR), set(KENLM_LIB), set(KENLM_UTIL_LIB), set(KENLM_INC)
Nothing worked, and i've been searching for a while know, so if you have some hints it would be great
-----------------------------------------------------------------------------------------------------------------------------------
**EDIT : I compiled boost for android but I dont succeed to do that with bzip2, I know have an error of this style **
-- Found BZip2: /usr/local/lib/libbz2.a (found version "1.0.8")
-- Looking for BZ2_bzCompressInit
-- Looking for BZ2_bzCompressInit - not found
I struggle to get GLFW Windows pre-compiled binaries working within my CLion Project. Those libraries are placed in a external directory. I do not want them to be in my project library but should (of course) be shipped when releasing the application. I am new to C++ but I thought to accomplish this might be as easy as it is in Java (Intellij Idea -> dependencies -> ...).
GLFW Windows pre-compiled binaries
I use MinGW 5.0 and CMake 3.10.2;
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
project(Hatsudouki_core)
set(CMAKE_CXX_STANDARD 17)
link_directories(F:\\C++\\ExternalLibraries\\GLFW\\lib-mingw-w64)
include_directories(F:\\C++\\ExternalLibraries\\GLFW\\include)
add_executable(Hatsudouki_core main.cpp)
target_link_libraries(Hatsudouki_core glfw3)
Main.cpp
#include <iostream>
#include <GLFW/glfw3.h>
int main() {
if (!glfwInit())
std::cout << "error!" << std::endl;
else
std::cout << "success!" << std::endl;
return 0;
}
Build output
"F:\C++\CLion 2018.1\bin\cmake\bin\cmake.exe" --build C:\Users\simon\CLionProjects\Hatsudouki-core\cmake-build-debug --target Hatsudouki_core -- -j 4
[ 50%] Linking CXX executable Hatsudouki_core.exe
CMakeFiles\Hatsudouki_core.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/simon/CLionProjects/Hatsudouki-core/main.cpp:5: undefined reference to `glfwInit'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Hatsudouki_core.exe] Error 1
CMakeFiles\Hatsudouki_core.dir\build.make:96: recipe for target 'Hatsudouki_core.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Hatsudouki_core.dir/all' failed
mingw32-make.exe[2]: *** [CMakeFiles/Hatsudouki_core.dir/all] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Hatsudouki_core.dir/rule' failed
mingw32-make.exe[1]: *** [CMakeFiles/Hatsudouki_core.dir/rule] Error 2
Makefile:117: recipe for target 'Hatsudouki_core' failed
mingw32-make.exe: *** [Hatsudouki_core] Error 2
I tried following solutions mentioned here:
- GLFW doc and GLFW doc2 (find package does not work, no CMake file)
- Github issue report related to Github issue report 2 which then leads to the solution to put FindGLFW.cmake into some directory? Tried to put it here GLFW\FindGLFW.cmake but does not work- Linking did not work as well as mentioned here: Stackoverflow
Image GLFW directory: GLFW Windows pre-compiled binaries
I think I just do not understand how CMake, external Libraries and C++ work together to accomplish this fairly easy task. I believe comparison to Java would help (used to work with gradle)
EDIT 1
As suggested I added following:
I put the Findglfw3.cmake into PROJECT/cmake/Modules/:
# Copyright (c) 2015 Andrew Kelley
# This file is MIT licensed.
# See http://opensource.org/licenses/MIT
# GLFW_FOUND
# GLFW_INCLUDE_DIR
# GLFW_LIBRARY
find_path(GLFW_INCLUDE_DIR NAMES F:\\C++\\ExternalLibraries\\GLFW\\include\\GLFW\\glfw3.h)
find_library(GLFW_LIBRARY NAMES glfw glfw3)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GLFW DEFAULT_MSG GLFW_LIBRARY GLFW_INCLUDE_DIR)
mark_as_advanced(GLFW_INCLUDE_DIR GLFW_LIBRARY)
And added following lines into my CMakeLists.txt:
find_package(glfw3 REQUIRED)
include_directories(${glfw3_INCLUDE_DIRS})
set(LIBS ${LIBS} ${glfw3_LIBRARIES})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
target_link_libraries(hatsudouki_core ${LIBS})
I also tried in the Findglfw3.cmake:
find_path(GLFW_INCLUDE_DIR NAMES GLFW/glfw3.h)
which is the same in the original file. Both do not work; error:
"F:\C++\CLion 2018.1\bin\cmake\bin\cmake.exe" --build C:\Users\simon\CLionProjects\Hatsudouki-core\cmake-build-debug --target Hatsudouki_core -- -j 4
CMake Error at CMakeLists.txt:6 (find_package):
-- Configuring incomplete, errors occurred!
By not providing "Findglfw3.cmake" in CMAKE_MODULE_PATH this project has
See also "C:/Users/simon/CLionProjects/Hatsudouki-core/cmake-build-debug/CMakeFiles/CMakeOutput.log".
asked CMake to find a package configuration file provided by "glfw3", but
CMake did not find one.
Makefile:175: recipe for target 'cmake_check_build_system' failed
Could not find a package configuration file provided by "glfw3" with any of
the following names:
glfw3Config.cmake
glfw3-config.cmake
Add the installation prefix of "glfw3" to CMAKE_PREFIX_PATH or set
"glfw3_DIR" to a directory containing one of the above files. If "glfw3"
provides a separate development package or SDK, be sure it has been
installed.
mingw32-make.exe: *** [cmake_check_build_system] Error 1
As explained here
Make Findglfw3.cmake file in PROJECT/cmake/Modules/ which looks like
# GLFW_FOUND
# GLFW_INCLUDE_DIR
# GLFW_LIBRARY
set(FIND_GLFW_PATHS "F:\\C++\\ExternalLibraries\\GLFW")
find_path(GLFW_INCLUDE_DIR NAMES GLFW/glfw3 GLFW/glfw3.h PATH_SUFFIXES include PATHS ${FIND_GLFW_PATHS})
find_library(GLFW_LIBRARY NAMES glfw3 glfw3.a libglfw3 libglfw3.a PATH_SUFFIXES lib-mingw PATHS ${FIND_GLFW_PATHS})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GLFW DEFAULT_MSG GLFW_LIBRARY GLFW_INCLUDE_DIR)
mark_as_advanced(GLFW_INCLUDE_DIR GLFW_LIBRARY)
Define Module Path in CMakeLists.txt
#Define module path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")
Also Link include directory and library with project in CMakeLists.txt
#Define static GLFW libraries and header files
find_package(glfw3 REQUIRED)
include_directories(${GLFW_INCLUDE_DIR})
...
target_link_libraries(Hatsudouki_core ${GLFW_LIBRARY})
At first you need to install glfw package. If you are using MSYS2 then it can be installed using pacman -S mingw-w64-x86_64-glfw on 64-bit windows and pacman -S mingw-w64-i686-glfw on 32-bit windows. And you need to use find_package to let the cmake locate the glfw library automatically instead of manually locating them. If you are not using MSYS2 then it might be little difficult. Check out this code.
cmake_minimum_required(VERSION 3.10)
project(Hatsudouki_core)
set(CMAKE_CXX_STANDARD 17)
add_executable(Hatsudouki_core main.cpp)
find_package(glfw3 REQUIRED) # Find the GLFW library
target_link_libraries(Hatsudouki_core PRIVATE glfw) # Finally, link to them.
I suggest you to use MSYS2 If you need pre-compiled libraries. It has a very good package manager called as pacman.
I'm building a project in Cpp that will communicate with my Java apps via rabbitmq and post updates to twitter. I'm using a few libraries from github
rabbitmq-c
Rabbit installed to /usr/local/lib64
jansson - json library
I installed this a while back for another project, went to /usr/local/lib
twitcurl - C lib for Twitter API
Got installed to /usr/local/lib
If it matters, I'm using CLion as my IDE, which displays jansson and rabbit under auto-complete when defining includes - so that's picking the libs off my system somehow
e.g.
#include <jansson.h>
#include <amqp.h>
I link them using the target_link_libraries(name libs...) and I see output saying
build$ cmake ..
CMake Error at CMakeLists.txt:30 (target_link_libraries):
Cannot specify link libraries for target "twitcurl" which is not built by
this project.
I set LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64
I try to set the CMAKE_LIBRARY_PATH to include usr/local/lib and lib64 but doesn't seem to have any effect. Here's my CMakeLists.txt file
#
# This is a CMake makefile. You can find the cmake utility and
# information about it at http://www.cmake.org
#
cmake_minimum_required(VERSION 2.6)
set(PROJECT_NAME twitterUpdater)
set(SOURCE_FILES main.cpp)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "/usr/local/lib"
"/usr/local/lib64")
project(${PROJECT_NAME})
find_package(X11 REQUIRED)
find_package(OpenCV REQUIRED)
IF (X11_FOUND)
INCLUDE_DIRECTORIES(${X11_INCLUDE_DIR})
LINK_LIBRARIES(${X11_LIBRARIES})
ENDIF ( X11_FOUND )
IF (OpenCV_FOUND)
include_directories(${OpenCV_INCLUDE_DIRS})
link_libraries(${OpenCV_LIBS})
ENDIF(OpenCV_FOUND)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${project_name} twitcurl jansson rabbitmq)
What's confusing me is another project I have uses jansson by simply adding it here TARGET_LINK_LIBRARIES(${project_name} dlib jansson)
What did I miss?? Thanks
CMake variables are case sensitive, thus the variable ${project_name} results in an empty string. Use ${PROJECT_NAME} instead, i.e.:
target_link_libraries(${PROJECT_NAME} twitcurl jansson rabbitmq)
Running CMake with the flag --warn-uninitialized helps you detect mistakes like this.
Im trying to build a vala-application together with an own library in the same project using CMake. Building the application works fine, so I've added a new "lib" directory to my project with the following CMakeLists.txt:
# Configure precompile
vala_precompile (LIB_VALA_C ${LIB_NAME}
Session.vala
PACKAGES
gio-2.0
gee-0.8
OPTIONS
--thread
--vapidir=${CMAKE_SOURCE_DIR}/vapi
--target-glib 2.32
GENERATE_VAPI
${LIB_NAME}
GENERATE_HEADER
${CMAKE_PROJECT_NAME}
)
# Add executable
add_library (${LIB_NAME} SHARED ${LIB_VALA_C})
# Set library properties
set_target_properties (${LIB_NAME} PROPERTIES
OUTPUT_NAME ${LIB_NAME}
VERSION ${LIB_SOVERSION}.${LIB_VERSION}
SOVERSION ${LIB_SOVERSION}
)
target_link_libraries (${LIB_NAME} ${LIB_LIBRARIES})
# Installation
install (TARGETS ${LIB_NAME} DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME}.pc DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig/)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME}.vapi DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/vala/vapi/)
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_NAME}.deps DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/vala/vapi/)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.h DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/${LIB_NAME}/)
The CMakeLists.txt in the project's root contains the following:
# Project name
project (drop)
# Minimum requirements of build-system
cmake_minimum_required (VERSION 2.8)
cmake_policy (VERSION 2.6)
# Global configuration
set (DATADIR "${CMAKE_INSTALL_PREFIX}/share")
set (PKGDATADIR "${DATADIR}/${CMAKE_PROJECT_NAME}")
set (GETTEXT_PACKAGE "${CMAKE_PROJECT_NAME}")
set (RELEASE_NAME "${CMAKE_PROJECT_NAME}")
set (VERSION "0.1")
set (VERSION_INFO "Release")
set (PREFIX ${CMAKE_INSTALL_PREFIX})
set (DOLLAR "$")
# Library configuration
set (LIB_VERSION 1.0)
set (LIB_SOVERSION 0)
set (LIB_NAME ${CMAKE_PROJECT_NAME}-${LIB_VERSION})
# Cmake-files
list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
# Configuration file
configure_file (${CMAKE_SOURCE_DIR}/dropd/config.vala.cmake ${CMAKE_SOURCE_DIR}/dropd/config.vala)
# Check for vala
find_package (Vala REQUIRED)
include (ValaVersion)
ensure_vala_version ("0.18" MINIMUM)
include (ValaPrecompile)
# Disable C compiler warnings
add_definitions (-w)
# Set gettext-package
add_definitions (-DGETTEXT_PACKAGE="${CMAKE_PROJECT_NAME}")
# Check for required dependencies
find_package (PkgConfig)
pkg_check_modules (DEPS REQUIRED granite gthread-2.0 gio-2.0 gee-0.8 avahi-gobject avahi-client)
# Link the avahi library
add_definitions (-lavahi)
# Link dependencies
add_definitions (${DEPS_CFLAGS})
add_definitions (${LIB_CFLAGS})
link_libraries (${DEPS_LIBRARIES})
link_directories (${DEPS_LIBRARY_DIRS})
link_directories (${LIB_LIBRARY_DIRS})
# Load directories
add_subdirectory (dropd)
add_subdirectory (lib)
add_subdirectory (po)
add_subdirectory (data)
add_subdirectory (schemas)
When building the project now the main application still builds without problems, but when the build of the library begins this error appears (translated):
make[2]: *** No rule to make »../lib/drop-1.0«,
required by »lib/drop-1.0«. End.
make[1]: *** [lib/CMakeFiles/drop-1.0.dir/all] Errors 2
make: *** [all] Errors 2
Badly Im not that familar with CMake and don't get what that error message means, neither what is causing it.
I have already compared my CMakeLists.txt files with them in another project that's also built out of a 'normal' application and one library, but I couldn't find the difference that makes my code not working: http://bazaar.launchpad.net/~wingpanel-devs/wingpanel/trunk/files/head:/
It would be very nice if you could give me some tips what I could have missed in the CMake-Files.
For the ones with the same problem: I've now solved the issue myself with removing the ${LIB_NAME} from the line vala_precompile (LIB_VALA_C ${LIB_NAME}. Im still not sure what's happening here, but this "solution" seemed to work.
Better ways to solve this issue are still appreciated. ;)