I'm pretty sure I'm doing something stupid here but when I try to go install boost from Cygwin's installer, I only see the -debug and -build options.
Cygwin Screenshot
I'm using the http://mirrors.sonic.net mirror. I switch to this from the default mirror because I thought that might have been the problem.
I know the package isn't getting installed because when I try to load my CMAKE file in clion, it throws and an error saying "Could NOT find Boost (missing: Boost_INCLUDE_DIR graph)".
Heres my CMakeLists.txt code:
cmake_minimum_required(VERSION 3.15)
project(HW_9)
set(CMAKE_CXX_STANDARD 14)
add_executable(HW_9 main.cpp knuth.txt graph_1.h)
# see https://cmake.org/cmake/help/latest/module/FindBoost.html
find_package(Boost REQUIRED COMPONENTS graph)
include_directories(${Boost_INCLUDE_DIR})
# Note: a target should be already defined using 'add_executable' or 'add_library'
target_link_libraries(HW_9 ${Boost_LIBRARIES})
Related
Following the instructions on their github repo I managed to build and install both libraries
paho-mqtt-c and paho-mqtt-cpp
in a custom directory
C:\mqtt\paho-c
C:\mqtt\paho-cpp
Now I'm trying to add those libraries in my project. My CMakelists.txt is as follows
cmake_minimum_required(VERSION 3.21)
enable_language(CXX)
list(APPEND CMAKE_PREFIX_PATH C:/mqtt/paho-cpp/lib/cmake/PahoMqttCpp)
find_package(PahoMqttCpp REQUIRED)
project(mqtt_test)
add_executable(mqtt_test main.cpp)
However, cmake insists on asking me where to find them.
Could NOT find PahoMqttC (missing: PAHO_MQTT_C_LIBRARIES PAHO_MQTT_C_INCLUDE_DIRS)
Why do I need to tell cmake again where to find C libraries? I think that was the job of find_package to also include those variables because I set it up on building and installation time.
Operating system: Windows 11 x64.
cmake version: 3.22.2
cmake generator: Ninja
C compiler: 11.2.0 (cygwin64)
C++ compiler: 11.2.0 (cygwin64)
EDIT: I manually specified the paths
set(PAHO_MQTT_C_LIBRARIES C:/mqtt/paho-c/lib/libpaho-mqtt3a-static.a)
set(PAHO_MQTT_C_INCLUDE_DIRS C:/mqtt/paho-c/include)
list(APPEND CMAKE_PREFIX_PATH C:/mqtt/paho-cpp/lib/cmake/PahoMqttCpp)
find_package(PahoMqttCpp REQUIRED)
However I'm getting a compilation error:
fatal error: mqtt/async_client.h: No such file or directory
61 | #include "mqtt/async_client.h"
I know how to solve it by manually adding the include paths in my cmakelist but I'm trying to figure out how to use their cmake module properly. find_package doesn't seem to do that.
Or I'm missing something.
I'm using CLion under pop_OS! 20.04 and am currently trying to get CMake to work with GLEW because I want to follow these tutorials to get started with OpenGL. I'm relatively new to C/C++ and completely new to CMake.
I installed the libgl1-mesa-dev,libglew-dev,libglfw3,libglfw3-dev packages with apt-get install and the glew.h is located alongside the other GL header files in /usr/include/GL.
When trying to compile a simple program:
#include <GL/glew.h>
int main() {
return 0;
}
cmake can't find the headerfile:
test/main.cpp:1:10: fatal error: GL/glew.h: No such file or directory
1 | #include <GL/glew.h>
| ^~~~~~~~~~~
Do I have to manually add these header files in CMakeLists.txt for cmake to find them? I tried like a dozen different suggestions but I didn't get it to work. For example, I tried
cmake_minimum_required(VERSION 3.17)
project(test)
set(CMAKE_CXX_STANDARD 14)
find_package(GLEW REQUIRED)
include_directories(${GLEW_INCLUDE_DIRS})
link_libraries(${GLEW_LIBRARIES})
target_link_libraries(test GLEW::GLEW)
but this results in
CMake Error at /app/extra/clion/bin/cmake/linux/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:164 (message):
Could NOT find GLEW (missing: GLEW_INCLUDE_DIRS GLEW_LIBRARIES)
Is this somehow a problem with CLion and I need to include libraries into my project in a different manner? Or am I using cmake in a wrong way?
Your last try was nearly right.
Forget about include_directories and link_libraries commands. All it needs when doing modern CMake is an add_executable(test main.cpp) followed by a target_link_libraries(test PRIVATE GLEW::glew) command. The target GLEW::glew (case matters here) bundles all compile definitions, include directories, libraries, and further settings that are needed to compile and link your example.
Your CMakeLists.txt would now look like this:
cmake_minimum_required(VERSION 3.17)
project(test)
set(CMAKE_CXX_STANDARD 14)
find_package(GLEW REQUIRED)
add_executable(myTest main.cpp)
target_link_libraries(myTest PRIVATE GLEW::glew)
Edit: Just noticed, that GLEW::GLEW can also be used.
The answer by #vre is OK. I only add how to find it yourself.
First, run
cmake --help-module-list
and look for GLEW. Under Linux, you can simplify this step to
cmake --help-module-list | grep -i Glew
where -i stands for "case insesitive match", as we usually don't remember if it's GLEW or perhaps Glew. Once you know the module name, you can ask for the specific help related to just this module:
cmake --help-module FindGLEW
The answer is there. Read and enjoy!
PS. There's no need to memorize this answer. All can be reduced to cmake --help.
I'm trying to use fltk library in my project but I have some troubles.
Here is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.12)
project(pp)
set(CMAKE_CXX_STANDARD 14)
add_executable(pp main.cpp)
FIND_PACKAGE(FLTK REQUIRED)
FIND_PACKAGE(GTK REQUIRED)
TARGET_LINK_LIBRARIES(pp ${FLTK_LIBRARIES})
TARGET_LINK_LIBRARIES(pp ${GTK_LIBRARIES})
FLTK version: 1.3.4
Cmake version: 3.7.2
I have installed fltk library in my /usr/local dirs
Include files are located in /usr/local/include/FL
I saw that the FindFLTK.cmake looks for following files:
FL/Fl.h or FL/Fl.H which the FL/Fl.h is located in /usr/local/include/FL so it can be found.
Here is the error message:
Could NOT find FLTK (missing: FLTK_INCLUDE_DIR)
Have you any ideas to solve this problem?
UPDATE
Current version of CMakeLists.txt
cmake_minimum_required(VERSION 3.7.2)
project(pp)
set(CMAKE_CXX_STANDARD 14)
add_executable(pp main.cpp)
target_include_directories(pp PRIVATE /usr/local/include/FL)
set (LIBRARIES fltk Xrender Xcursor Xfixes Xext Xft fontconfig Xinerama pthread dl m X11)
message(STATUS mess: ${CMAKE_MODULE_PATH})
target_link_libraries(pp ${LIBRARIES})'
In this configuration I can compile, and link executable, but why configuration with FIND_PACKAGE does not work? Where I should look for a bug?
Probably bad installation of library. I just installed fresh one from GitHub sources with CMake configuring by cmake -G "MinGW Makefiles" . with followed make and make install to install it in compiler library I suppose.
After that errors containing Could NOT find FLTK (missing: FLTK_INCLUDE_DIR) has disappeared in compilation of another project. I suppose, cmake error report is not so strict and clarified, i.e. this error means some exception in FindFLTK.cmake and not exactly about missing FLTK_INCLUDE_DIR.
I am not a C++ programmer, only have made a course a while ago. Using homebrew I installed libbitcoin and was hoping that I can reference the library like I was able to reference the boost libraries. I also realized that there are no links in /usr/local/bin to the Cellar.
I think I could get it working by using the absolute paths but I am looking for the proper way of handling this constellation that I just mentioned.
Current CMake:
cmake_minimum_required(VERSION 2.8.4)
project(cplusplus)
message(STATUS "start running cmake...")
find_package(boost 1.65.1 COMPONENTS system filesystem REQUIRED)
find_package(libbitcoin 3.3.0 COMPONENTS system filesystem REQUIRED)
message("system: ${CMAKE_SYSTEM_PREFIX_PATH}")
find_library(LIB_BITCOIN libbitcoin)
message("bitcoin: ${LIB_BITCOIN}")
if(Boost_FOUND)
message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
message(STATUS "Boost_VERSION: ${Boost_VERSION}")
include_directories(${Boost_INCLUDE_DIRS})
endif()
add_executable(cplusplus main.cpp)
if(Boost_FOUND)
target_link_libraries(cplusplus ${Boost_LIBRARIES})
endif()
Currently I get these errors:
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /Users/johndow/Documents/Workspace/bitcoin-code/cplusplus
-- start running cmake...
-- Boost version: 1.65.1
CMake Error at CMakeLists.txt:8 (find_package):
By not providing "Findlibbitcoin.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"libbitcoin", but CMake did not find one.
Could not find a package configuration file provided by "libbitcoin"
(requested version 3.3.0) with any of the following names:
libbitcoinConfig.cmake
libbitcoin-config.cmake
Add the installation prefix of "libbitcoin" to CMAKE_PREFIX_PATH or set
"libbitcoin_DIR" to a directory containing one of the above files. If
"libbitcoin" provides a separate development package or SDK, be sure it has
been installed.
-- Configuring incomplete, errors occurred!
See also "/Users/johndoe/Documents/Workspace/bitcoin-code/cplusplus/cmake-build-debug/CMakeFiles/CMakeOutput.log".
[Finished]
You seem to have double lookup for libbitcoin library in your CMakeLists file. You are first looking for it by:
find_package(libbitcoin ...)
and then by
find_library(LIB_BITCOIN libbitcoin)
Cmake is not happy (as your error message says) with the find_package() clause as libbitcoin does not provide cmake configuration by itself. You have many ways how to fix it, just two of them:
remove find_package() and use only find_library(), I think this is the simpler way and your project should work this way
provide cmake configuration for libbitcoin by yourself. Good introduction how to do this is here (and good to read anyway):
https://cmake.org/Wiki/CMake:How_To_Find_Libraries
As far as I know, currently libbitcoin does not export any <libbitcoin>Config.cmake package.
But it does export a libbitcoin.pc file for generic use with pkg-config.
ie: /usr/local/lib/pkgconfig/libbitcoin.pc
If you get results from invoking pkg-config --cflags libbitcoin then it's there.
And then you can put something like this in your CMakeLists.txt:
#use this if libbitcoin is installed to some custom location
set(ENV{PKG_CONFIG_PATH} "/path/to/libbitcoin/pkgconfig/:$ENV{PKG_CONFIG_PATH}")
#then later..
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIB_BITCOIN REQUIRED libbitcoin)
#then later..
target_link_libraries(${PROJECT_NAME} PRIVATE ${LIB_BITCOIN_LIBRARIES})
target_include_directories(${PROJECT_NAME} PRIVATE ${LIB_BITCOIN_INCLUDE_DIRS})
That should pull in boost, make the libbitcoin includes visible and solve all manner of compiler and linker woes.
(Or if you are feeling mad, you could always make use of this gist).
I am setting up GLFW and Vulkan for a project of mine. For Vulkan I am using MoltenVk to get Vulkan compat and GLFW for the window creation. The IDE I am using is CLion, which uses the CMake system.
Judging from some github issues, there seems to be support for this setup, but nobody there mentions how it is done.
GLFW is installed through homebrew and MoltenVK manually by adding the MoltenVK and vulkan folders to usr/local/include and the contents of the MacOS folder to usr/local/lib (even though I am quite sure MoltenVK.framework should not be there).
At this point, Clion can see the GLFW and Vulkan headers, but I still need to link them up properly.
the full CMakeLists.txt file is this now:
cmake_minimum_required(VERSION 3.8)
project(VulkanEngine)
#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} “${CMAKE_SOURCE_DIR}/cmake/Modules”)
set(CMAKE_CXX_STANDARD 17)
set(SOURCE_FILES src/main.cpp)
add_executable(VulkanEngine ${SOURCE_FILES})
#Finding and linking GLFW3
find_package(glfw3 3.2 REQUIRED)
if (glfw3_FOUND)
include_directories(${glfw3_INCLUDE_DIRS})
target_link_libraries (VulkanEngine ${glfw3_LIBRARIES})
endif (glfw3_FOUND)
#Finding and linking Vulkan
find_package (Vulkan)
if (Vulkan_FOUND)
include_directories(${Vulkan_INCLUDE_DIRS})
target_link_libraries (VulkanEngine ${Vulkan_LIBRARIES})
endif (Vulkan_FOUND)
the console tells the following when the cmake project has been reloading:
-- Could NOT find Vulkan (missing: Vulkan_LIBRARY)
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/mtesseract/dev/cpp/VulkanEngine/cmake-build-debug
to me this indicates that GLFW has been found and linked, but when I try to build the "hello world" for GLFW, I get the following message:
Undefined symbols for architecture x86_64:
"_glfwInit", referenced from:
_main in main.cpp.o
I got FindVulkan.cmake from the GLFW github page https://git.io/v5ggN, since it has support for MoltenVK, but I am not sure if it is picked up by CMake at all. (I put the file in (projectroot)/cmake/modules/)
At this point, I am out of ideas as to why things are not linking properly, so help is appreciated.
I have found a solution that at least till some degree seems to work. At this point I have another problem to take care of (GLFW doesn't seem to pick up on MoltenVK's presence).
The process thus far is as follows (and can be found on my github page (github.com/mtesseracttech/VulkanEngine):
Vulkan + GLFW + GLM Setup Process with CMake and Package Managers
Windows:
Preparation:
Create CLion Application Project
Install MSYS2 (Cygwin-like package manager that includes a windows port of Arch's PacMan)
Install LunarG VK SDK
Download FindVulkan.cmake from GFLW's Github (it includes a path for MoltenVK(for OSX Later)) and put it in (proj_root/cmake/modules)
MSYS2 Commands:
$ pacman -Su //Updates pacman
$ pacman -Ss {packageName} //Is used for searching for exact package names
Installed Packages through msys2:
$ pacman -S mingw-w64-x86_64-toolchain //Installs the CLion toolchain that includes CMake, Make, GCC, etc.
$ pacman -S mingw-w64-x86_64-glfw //Installs GLFW
$ pacman -S mingw-w64-x86_64-glm //Installs GLM
$ pacman -S mingw-w64-x86_64-vulkan //Vulkan can also be installed through this method, but I went with LunarG
Enter the following in the CMakeLists.txt file in the root of the project:
######################################################################################
cmake_minimum_required(VERSION 3.8)
project(VulkanEngine)
set(CMAKE_CXX_STANDARD 17)
set(SOURCE_FILES src/main.cpp)
add_executable(VulkanEngine ${SOURCE_FILES})
#Setting up PkgConfig
find_package(PkgConfig REQUIRED)
#Finding and linking GLFW3
pkg_search_module(GLFW3 3.2 REQUIRED glfw3)
if(GLFW3_FOUND)
message(STATUS "Found GLFW, Including and Linking now")
include_directories(${GLFW3_INCLUDE_DIRS})
target_link_libraries(VulkanEngine ${GLFW3_STATIC_LIBRARIES})
endif(GLFW3_FOUND)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
#Finding and linking Vulkan
find_package (Vulkan)
if (VULKAN_FOUND)
message(STATUS "Found Vulkan, Including and Linking now")
include_directories(${VULKAN_INCLUDE_DIR})
target_link_libraries (VulkanEngine ${VULKAN_LIBRARY})
endif (VULKAN_FOUND)
######################################################################################
OSX:
Preparation
Create CLion Application Project
Install HomeBrew (package manager)
Download MoltenVK
Download FindVulkan.cmake from GFLW's Github (it includes a path for MoltenVK(for OSX Later)) and put it in (proj_root/cmake/modules)
Homebrew:
brew update //Updates homebrew
brew install glfw //Installs GLFW
brew install glm //Installs GLM
MoltenVK:
Place MoltenVK/macOS's contents into /usr/local/lib
Place MoltenVK/macOS/MoltenVK.framework/headers's contents into /usr/local/inc/MoltenVK
CMake:
Same as on windows, but in the FindVulkan.cmake file, add at the very end of the elseif(APPLE) block the line:
set(VULKAN_INCLUDE_DIR "/usr/local/include/MoltenVK")
This is not a pretty or flexible solution, but for now it will do.
I am pretty sure this solution is not ideal since GLFW isn't picking up on MoltenVK with this tactic, but at least things compile, so I see that as progress.
Seems your issue is that you haven’t defined the VULKAN_SDK variable. Make sure you point this to the parent folder of /lib & /include inside the SDK and FindVulkan should work
VULKAN_SDK=/opt/vulkan/x86_64 cmake.