So this is where my boost library path (where all .hpp files are):
/usr/local/Cellar/boost/1.80.0/include/boost
How should I set this up in Clion to start using <boost/.*> as headers in cpp files?
This is how my CMakeList.txt looks like:
cmake_minimum_required(VERSION 3.24)
project(laboratorium_1)
set(CMAKE_CXX_STANDARD 17)
set(BOOST_ROOT "/usr/local/Cellar/boost/1.80.0")
find_package(Boost 1.80.0)
set(BOOST_INCLUDEDIR "/usr/local/Cellar/boost/1.80.0/include")
find_package(Boost 1.80.0 COMPONENTS system filesystem REQUIRED)
if(NOT Boost_FOUND)
message(FATAL_ERROR "Could not find boost!")
endif()
add_executable(laboratorium_1 main.cpp Faktura.cpp Faktura.h Produkt.cpp Produkt.h PozycjaFaktury.cpp PozycjaFaktury.h)
It does not work.
cmake_minimum_required(VERSION 3.24)
project(laboratorium_1)
set(CMAKE_CXX_STANDARD 17)
set(BOOST_ROOT /usr/local/Cellar/boost/1.80.0)
set(BOOST_INCLUDEDIR /usr/local/Cellar/boost/1.80.0/include)
set(BOOST_LIBRARY_DIR /usr/local/Cellar/boost/1.80.0/lib)
find_package(Boost 1.80.0 COMPONENTS system filesystem REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
if(NOT Boost_FOUND)
message(FATAL_ERROR "Could not find boost!")
endif()
add_executable(laboratorium_1 main.cpp Faktura.cpp Faktura.h Produkt.cpp Produkt.h PozycjaFaktury.cpp PozycjaFaktury.h)
The last comment on this thread contains a solution which worked for me:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206607995-Does-CLion-support-boost-library-
Related
Find_package command is a nightmare to me.
I am trying to include some specified components in boost into my project.
Some components could not be found with find_package command for different error.
Can anyone help to explain the error reported?
case 1:
cmake_minimum_required(VERSION 3.15)
project(tryBoost)
set(CMAKE_CXX_STANDARD 14)
set(BOOST_ROOT "D:\\cygwin64\\home\\yubo\\boost_1_62_0") # either set it here or from the command line
find_package(Boost 1.62.0 REQUIRED COMPONENTS json) # header only libraries must not be added here
add_executable(tryBoost main.cpp)
I try to find json, but error reported:
No header defined for json; skipping header check
case 2:
cmake_minimum_required(VERSION 3.15)
project(tryBoost)
set(CMAKE_CXX_STANDARD 14)
set(BOOST_ROOT "D:\\cygwin64\\home\\yubo\\boost_1_62_0") # either set it here or from the command line
find_package(Boost 1.62.0 REQUIRED COMPONENTS system) # header only libraries must not be added here
add_executable(tryBoost main.cpp)
I try to find system, but error reported:
Could NOT find Boost (missing: Boost_INCLUDE_DIR system)
How boost organizes its components in sub dirs? How find_package command works when scaning boost root dir? why "header only libraries must not be added here".
thanks.
Please use below CMakeList.txt for reference.
cmake_minimum_required(VERSION 3.15)
project(tryBoost)
set(CMAKE_CXX_STANDARD 14)
#set(Boost_DEBUG ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(BOOST_ROOT "/home/yubo/boost_1_78_0")
add_executable(tryBoost main.cpp)
set(Boost_NO_BOOST_CMAKE FALSE CACHE BOOL "" FORCE)
find_package(Boost 1.78.0 REQUIRED COMPONENTS json)
message("${Boost_FOUND}")
message("Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
target_include_directories(tryBoost PUBLIC ${Boost_INCLUDE_DIRS})
message("Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
message("Boost_LIBRARIES: ${Boost_LIBRARIES}")
target_link_libraries(tryBoost ${Boost_LIBRARIES})
I'm developing a cpp project in Clion. For the build I use cmake. Last weekend I upgraded from ubuntu 18.04 to 20.04, from then I cannot build my project and I get the error:
/usr/local/include/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'. It seems that something in the linking isn't right. I reinstalled all packages, tried different versions but nothing. My CMakeLists.txt is:
cmake_minimum_required(VERSION 3.7)
project(pki_cpp)
set(CMAKE_CXX_STANDARD 11)
set(THREADS_PREFER_PTHREAD_FLAG ON)
#find_package(libmongocxx REQUIRED)
find_package(mongocxx REQUIRED)
find_package(bsoncxx REQUIRED)
include_directories(${LIBMONGOCXX_INCLUDE_DIR})
include_directories(${LIBBSONCXX_INCLUDE_DIR})
include_directories(SYSTEM ./lib)
set(BOOST_ROOT /usr/lib/)
find_package(Boost 1.71.0 REQUIRED COMPONENTS system chrono thread filesystem)
include_directories(${Boost_INCLUDE_DIR})
if(NOT Boost_FOUND)
message(FATAL_ERROR "Could not find boost!")
endif()
find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)
# A custom library
add_subdirectory(asnDatatypes)
include_directories({CMAKE_CURRENT_SOURCE_DIR} asnDatatypes)
set_property(TARGET asnLibrary PROPERTY POSITION_INDEPENDENT_CODE ON)
# end custom library
#cryptopp library
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/contrib/cmake")
find_package(CryptoPP REQUIRED)
include_directories(${CRYPTOPP_INCLUDE_DIR})
link_directories(${CryptoPP_INCLUDE_DIR})
# end cryptopp
add_executable(pki_cpp main.cpp rootCA.cpp rootCA.h)
target_include_directories(pki_cpp PRIVATE ${Boost_INCLUDE_DIRS} ${LIBMONGOCXX_INCLUDE_DIRS} )
link_directories(pki_cpp ${Boost_LIBRARY_DIRS})
target_link_libraries(pki_cpp ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LIBRARIES} Boost::system Threads::Threads boost_system asnLibrary OpenSSL::SSL ${CRYPTOPP_LIBRARIES} ${LIBMONGOCXX_LIBRARIES} mongo::bsoncxx_shared mongo::mongocxx_shared ${CMAKE_THREAD_LIBS_INIT} ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} Boost::system)
Any help is appreciated!
That's a lot of stuff, all randomly ordered and commented out. The obvious error is a failure to link Boost System
I'd go with
FIND_PACKAGE(Boost 1.65.0
COMPONENTS system program_options REQUIRED)
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
INCLUDE_DIRECTORIES(${Boost_INLUDE_DIRS})
LINK_LIBRARIES(${Boost_LIBRARIES})
Alternatively you can be specific and link specific libs to specific targets
TARGET_LINK_LIBRARIES(mylib ${Boost_SYSTEM_LIBRARY})
TARGET_LINK_LIBRARIES(myexecutable ${Boost_THREAD_LIBRARY})
My project structure looks like this:
CMakeLists.txt
deps
glew
glfw
include
src
...
graphics
...
CMakeLists.txt
Two CMakeLists.txt files that deserve attention:
CMakeLists.txt
cmake_minimum_required(VERSION 3.9)
project(noam_engine)
find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
set(CMAKE_CXX_STANDARD 11)
set(NE_LIBRARIES common math graphics)
FOREACH(lib ${NE_LIBRARIES})
add_subdirectory(src/${lib})
ENDFOREACH(lib)
add_executable(noam_engine src/main.cpp)
if(OPENGL_FOUND AND GLEW_FOUND)
target_include_directories(noam_engine PUBLIC include ${OPENGL_INCLUDE_DIR} ${GLEW_INCLUDE_DIRS})
target_link_libraries(noam_engine ${NE_LIBRARIES})
endif()
src/graphics/CMakeLists.txt
cmake_minimum_required(VERSION 3.9)
find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
file(GLOB SRC "*.cpp")
add_library(graphics ${SRC})
if(OPENGL_FOUND AND GLEW_FOUND)
target_include_directories(graphics PUBLIC ${PROJECT_SOURCE_DIR}/include ${OPENGL_INCLUDE_DIR} ${GLEW_INCLUDE_DIRS})
target_link_libraries(graphics ${OPENGL_gl_LIBRARY} ${GLFW3_LIBRARY} ${GLEW_LIBRARIES})
message(STATUS "GLFW and GLEW successfully linked")
message(STATUS ${OPENGL_gl_LIBRARY})
message(STATUS ${GLFW3_LIBRARY})
message(STATUS ${GLEW_LIBRARIES})
else()
message(STATUS "Cannot find GL libraries")
endif()
In a few words I want to create a bunch of static libraries of the engine, in particular, link graphics library with GL's, and finally link all of them with the executable in a root CMakeLists.txt.
But I noticed that ${GLFW3_LIBRARY} is empty and I got a linker error, for example, when I call glfwInit(). I followed the guide during building and installation of GLFW
cmake .
make
make install
I believe headers and libraries are in /usr/local/*, but apparently CMake cannot find them or maybe I did something wrong.
The only hypothesis I have is that find_package doesn't know about glfw3Config.cmake which is in deps/glfw/*
I took the script from https://github.com/JoeyDeVries/LearnOpenGL/blob/master/cmake/modules/FindGLFW3.cmake and put it into cmake folder. Then in CMakeLists.txt I added
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
Now everything works properly
Thanks #Tsyvarev
I'm trying to run travis test,but I get the following error.
I checked my files and directories, all files are exist.
I think my mistake in cmake file, but I can't find it.
Maybe someone can help me?
make[1]: *** No rule to make target CMakeFiles/test.dir/all', needed byCMakeFiles/Examples.dir/all'. Stop.
cmake_minimum_required(VERSION 2.8.7)
project(test)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
option(BUILD_SHARED_LIBS "Build shared instead of static library" OFF)
option(BUILD_TESTS "Build tests for webdavclient" ON)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/tests/ /sources)
add_library(test STATIC ${CMAKE_CURRENT_SOURCE_DIR}/sources/client.cpp tests/main.cpp)
find_package(OpenSSL REQUIRED)
find_package(Boost REQUIRED)
find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIR})
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(test ${Boost_LIBRARIES})
endif()
if(UNIX)
set(DEPENDS_LIBRARIES ${OPENSSL_LIBRARIES} ${CURL_LIBRARY} ${Boost_LIBRARIES})
elseif(MSVC)
set(DEPENDS_LIBRARIES ${OPENSSL_LIBRARIES} ${CURL_LIBRARY} ${Boost_LIBRARIES} ws2_32)
endif()
add_executable(Examples ${CMAKE_CURRENT_SOURCE_DIR}/examples/main.cpp)
target_link_libraries(Examples ${PROJECT_NAME} ${DEPENDS_LIBRARIES})
if(BUILD_TESTS)
enable_testing()
file(GLOB ${PROJECT_NAME}_TEST_SOURCES tests/*.cpp)
add_executable(init ${${PROJECT_NAME}_TEST_SOURCES})
target_link_libraries(init ${PROJECT_NAME} ${DEPENDS_LIBRARIES})
add_test(NAME init COMMAND init "-s" "-r" "compact" "--use-colour" "yes")
endif()
Command enable_testing() among other things creates target test. But you already have library target with the same name. This confuses CMake. For avoid this, rename library target.
Also, it is not recommended to have target name same as the project. So, rename project too.
I have a very simple boost application:
#include <iostream>
#include "boost/filesystem.hpp"
int main(int /*argc*/, char** /*argv*/) {
if( boost::filesystem::exists(".") )
std::cout << "exists" << std::endl;
return 0;
}
Which I configure with CMake:
cmake_minimum_required (VERSION 2.8 FATAL_ERROR)
set(USE_BOOST_LIB_HACK TRUE)
#--- Boost (TODO: wrong libraries linked)
find_package (BOOST COMPONENTS filesystem system REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
if(USE_BOOST_LIB_HACK)
#--- Now I need to manually append them to avoid missing symbols
list(APPEND libs /usr/local/lib/libboost_system.dylib)
list(APPEND libs /usr/local/lib/libboost_filesystem.dylib)
else()
list(APPEND libs ${Boost_LIBRARIES})
message(STATUS BOOST: ${Boost_LIBRARIES}) #<<< EMPTY :( :(
endif()
#--- Add all sources in this folder
file(GLOB_RECURSE hdrs "*.h")
file(GLOB_RECURSE srcs "*.cpp")
#--- Create executable and link
set(CMAKE_BUILD_TYPE "Debug")
add_executable(boost ${hdrs} ${srcs})
target_link_libraries(boost ${libs})
Note tha hack USE_BOOST_LIB_HACK in the file above. But shouldn't Boost_LIBRARIES have what I need? In the configure above it's a trivial empty string. I am using {cmake,boost1.5} from OSX/Homebrew
Is my configuration somehow incorrect?
Thanks!
CMake is case-sensitive. Use find_package(Boost ...) but not find_package(BOOST ...).
BTW COMPONENTS suboption is optional if REQUIRED used:
find_package(Boost REQUIRED filesystem system)
Possible explanation: http://pastebin.com/qQyGnQDL
Here's how the documentation from FindBoost.cmake describes proper usage of the macro:
#
# set(Boost_USE_STATIC_LIBS ON)
# set(Boost_USE_MULTITHREADED ON)
# set(Boost_USE_STATIC_RUNTIME OFF)
# find_package( Boost 1.36.0 COMPONENTS date_time filesystem system ... )
#
# if(Boost_FOUND)
# include_directories(${Boost_INCLUDE_DIRS})
# add_executable(foo foo.cc)
# target_link_libraries(foo ${Boost_LIBRARIES})
# endif()
And this method works well on Linux indeed. But I'm not sure about MacOSX/HomeBrew, although it's not mentioned specifically in the macro.