I have installed boost-variant2 library using the vcpkg command:
vcpkg install boost-variant2:x64-windows
When vcpkg finished the installation, it prompted this:
The package boost is compatible with built-in CMake targets:
find_package(Boost REQUIRED [COMPONENTS <libs>...])
target_link_libraries(main PRIVATE Boost::boost Boost::<lib1> Boost::<lib2> ...)
so in my CMakeLists.txt I added the following lines:
find_package(Boost COMPONENTS variant2 REQUIRED)
target_link_libraries(MyTarget PRIVATE Boost::variant2)
However, when I run cmake -DCMAKE_TOOLCHAIN_FILE:STRING=/path_to_vcpkg/scripts/buildsystems/vcpkg.cmake I get the following error:
-- Configuring incomplete, errors occurred!
Could NOT find Boost (missing: variant2) (found version "1.78.0")
Looks like variant2 is header-only lib and you can just use Cmake file like this:
cmake_minimum_required(VERSION 3.5)
project(project LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Boost)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(project main.cpp)
U can see list of libs required to be built for here for Windows and here for Unix-like systems
Related
Facebook's wangle library can be set up with cmake like below:
set_and_check(WANGLE_INCLUDE_DIR /usr/local/include/wangle)
set_and_check(WANGLE_CMAKE_DIR /usr/local/lib/cmake/wangle)
if (NOT TARGET wangle::wangle)
include("${WANGLE_CMAKE_DIR}/wangle-targets.cmake")
endif()
set(WANGLE_LIBRARIES wangle::wangle)
if (NOT wangle_FIND_QUIETLY)
message(STATUS "Found wangle: ${PACKAGE_PREFIX_DIR}")
endif()
However, proxygen's install.sh doesn't put the include and lib files in /usr/local like wangle and other fb libraries do.
What is the proper way to set the include and link with proxygen via cmake?
According to the proxygen README you should install all requirements, including folly, wangle, fmt, fizz, and mvfst if you need HTTP/3 protocol. After installing proxygen with the instruction in the README you can use it in your CMake project. Following is an example CMakeLists.txt and you can find the complete sample project in this repo.
cmake_minimum_required(VERSION 3.10)
project(3hat)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(proxygen REQUIRED)
find_package(gflags REQUIRED)
add_subdirectory(server)
I'm setting up a C++17 project in CLion and i wanted to use java native interface, but here comes the problem. FindJNI.cmake fails with error:
Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2)
Ive tried to manually set JAVA_INCLUDE_PATH in my CMakeLists.txt using:
set(JAVA_INCLUDE_PATH "$ENV{JAVA_HOME}/include") (and the same with PATH2), it only partly solves the problem because then cmake output is Found JNI: /usr/lib/jvm/default/lib/amd64/libjawt.so
My CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(project1)
set(CMAKE_CXX_STANDARD 17)
find_package(JNI REQUIRED)
add_executable(project1 main.cpp)
NOTE: I have JAVA_HOME set to /usr/lib/jvm/java-8-openjdk and java-8-openjdk package installed from AUR.
Have you tried adding includes with this one
include_directories( ${CMAKE_JAVA_} $ENV{JAVA_HOME}/include $ENV{JAVA_HOME}/include/linux )
I am previously using Visual Studio with NuGet for all package. Now I change to CMake.
Now I am using vcpkg to manage library.
However, I need OpenGl
The command of Cmake to link freeglut, glew, glm, libpng, zlib was provide by vcpkg. But not OpenGL.
cmake_minimum_required(VERSION 3.0)
project(little_plane)
set(CMAKE_CXX_STANDARD 14)
add_executable(little_plane main.cpp)
# ./vcpkg install freeglut
find_package(GLUT REQUIRED)
target_link_libraries(little_plane PRIVATE GLUT::GLUT)
## ./vcpkg install glew
#find_package(GLEW REQUIRED)
#target_link_libraries(little_plane PRIVATE GLEW::GLEW)
#
# glm
find_package(glm CONFIG REQUIRED)
target_link_libraries(little_plane PRIVATE glm)
# ./vcpkg install libpng
find_package(PNG REQUIRED)
target_link_libraries(little_plane PRIVATE PNG::PNG)
##
find_package(ZLIB REQUIRED)
target_link_libraries(little_plane PRIVATE ZLIB::ZLIB)
find_package(OpenGL REQUIRED)
if (OPENGL_FOUND)
message("opengl found")
message("include dir: ${OPENGL_INCLUDE_DIR}")
message("link libraries: ${OPENGL_gl_LIBRARY}")
else (OPENGL_FOUND)
message("opengl not found")
endif()
target_link_libraries(little_plane ${OPENGL_gl_LIBRARY})
find_package(glfw3 CONFIG REQUIRED)
target_link_libraries(little_plane PRIVATE glfw)
With the CMakeLists.txt above, I run cmake .
opengl found
include dir: /usr/include
link libraries: /usr/lib/x86_64-linux-gnu/libGL.so
CMake Error at CMakeLists.txt:40 (target_link_libraries):
The keyword signature for target_link_libraries has already been used with
the target "little_plane". All uses of target_link_libraries with a target
must be either all-keyword or all-plain.
The uses of the keyword signature are here:
* CMakeLists.txt:10 (target_link_libraries)
* CMakeLists.txt:20 (target_link_libraries)
* CMakeLists.txt:24 (target_link_libraries)
* CMakeLists.txt:28 (target_link_libraries)
CMake Error at CMakeLists.txt:44 (target_link_libraries):
The plain signature for target_link_libraries has already been used with
the target "little_plane". All uses of target_link_libraries with a target
must be either all-keyword or all-plain.
The uses of the plain signature are here:
* CMakeLists.txt:40 (target_link_libraries)
-- Configuring incomplete, errors occurred!
Which mean opengl is installed on my system. I just don't know how to use target_link_libraries to link with my project.
Provide answer that can copy and paste into CMakeLists.txt if possible.
All your previous target_link_libraries contain a transitivity keyword (PRIVATE in all cases), but you have not provided any when linking OpenGL. So just add that too:
target_link_libraries(little_plane PRIVATE ${OPENGL_gl_LIBRARY})
Using the following CMake code:
cmake_minimum_required(VERSION 3.6)
project(TrustLineManager)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(BOOST_ROOT D:/Tools/boost_1_62_0/)
set(Boost_INCLUDE_DIRS D:/Tools/boost_1_62_0/boost)
set(Boost_LIBRARY_DIRS D:/Tools/boost_1_62_0/libs)
set(BOOST_INCLUDEDIR C:/MinGW/include)
set(BOOST_LIBRARYDIR C:/MinGW/lib)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost
1.62.0
COMPONENTS system
filesystem
REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(TrustLineManager ${Boost_LIBRARIES})
I get this error:
Error:Unable to find the requested Boost libraries.
Boost version: 1.62.0
Boost include path: D:/Tools/boost_1_62_0
Could not find the following static Boost libraries:
boost_system boost_filesystem
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.
What should I do to solve it?
EDIT:
I modified my CMake code into:
cmake_minimum_required(VERSION 3.6)
project(TrustLineManager)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
set(BOOST_ROOT "D:/Tools/boost_1_62_0")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(TrustLineManager ${SOURCE_FILES})
target_link_libraries(TrustLineManager Boost::filesystem Boost::thread)
I have now this error:
Error:Target "TrustLineManager" links to target "Boost::filesystem" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?
Here is a screenshot of Boost directory contents:
Obviously CMake finds Boost as it is able to detect its version (1.62.0).
CMake uses the file FindBoost.cmake to determine what libraries to link against.
This file is updated continuously when new boost versions appear.
There, support for Boost 1.62.0 is available only for CMake >= 3.7.0.
So just update your CMake version (or just the file FindBoost.cmake) and you will be fine.
I have been working on a library in C++ and have run into a bit of difficulty trying to integrate boost into my project. I kept the message that boost could not be found, but on the other hand, my fellow developer using Arch had no issues.
We figured out that this is because Linux Mint (at least with the libboost-all-dev package) installs the libraries to /usr/lib/x86_64-linux-gnu which is not searched by the FindBoost module. We fixed this by creating symbolic links:
ln -s /usr/lib/x86_64-linux-gnu/libboost* /usr/lib/
What I want to know: is there a better (more acceptable) way of fixing this because when I compile major projects, I do not run into this problem.
Here is CMakeLists.txt (with some omissions)
cmake_minimum_required(VERSION 2.8)
project(testlibrary CXX)
set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.55.0 COMPONENTS unit_test_framework thread log REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
add_library(testlibrary STATIC ${SOURCE_MAIN})
target_link_libraries(testlibrary ${Boost_LIBRARIES})
You can set the hint BOOST_LIBRARYDIR:
set(BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu")
find_package(Boost 1.55.0 COMPONENTS unit_test_framework thread log REQUIRED)
Alternative, you can set this when running CMake like this:
cmake -DBOOST_LIBRARYDIR="/usr/lib/x86_64-linux-gnu" <project_root>
If you just run:
cmake <project_root>
then FindBoost.cmake will look in the usual spots for your boost libaries.
See the documentation of FindBoost.cmake for your CMake version here.