I need to use custom build of boost lib, which uses own library naming prefix as well as namespace in the code.
I need to link with it in CMakeLists.txt:
set(BOOST_INCLUDEDIR /path/to/custom/boost/include)
set(BOOST_LIBRARYDIR /path/to/custom/boost/lib)
set(BOOST_NAMESPACE my_boost_161)
set(Boost_NO_SYSTEM_PATHS OFF)
set (Boost_USE_STATIC_LIBS OFF)
find_package (Boost REQUIRED COMPONENTS my_unit_test_framework)
include_directories (${Boost_INCLUDE_DIRS})
the libraries have a names like :
libmy_boost_161_unit_test_framework.so
and really exist in lib folder
there is a errors like:
CMake Error at
/home/user1/.localcmake/share/cmake-3.14/Modules/FindBoost.cmake:2132
(message): Unable to find the requested Boost libraries.
Boost version: 1.61.0
Boost include path:
/path/to/custom/boost/include
Could not find the following Boost libraries:
boost_unit_test_framework
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
How can I specify to look for libs with names like (my_ addition to standard names):
similar to Boost_LIB_VERSION which gives an ability to add the version to lib name
my_boost_161_unit_test_framework
This addition to the CMake script fixes the problem:
...
set(Boost_NO_SYSTEM_PATHS OFF)
set(Boost_LIB_PREFIX my_boost_161)
set(Boost_NAMESPACE my_boost_161)
set(Boost_USE_STATIC_LIBS OFF)
...
Related
Here is my CMakeLists.txt file
cmake_minimum_required(VERSION 3.8)
project("pi-calc" VERSION 1.0)
find_package(Boost REQUIRED COMPONENTS multiprecision)
add_executable(pi-calc main.cpp)
target_link_libraries(pi-calc PRIVATE Boost::boost Boost::multiprecision)
This is the main part of error message, removing CMake find_package failure Call Stacks
Could NOT find Boost (missing: multiprecision) (found version "1.67.0")
I have tried googling around for a solution but couldn't find anything.
Many of Boost's libraries are header-only libraries, including the multiprecision library. You only need to explicitly call out the libraries in COMPONENTS that are not header-only, shown in the list here.
If you need a header-only library, such as multiprecision, you will get this for free from the Boost::boost target, which includes all the Boost headers. There is no need to list any COMPONENTS:
cmake_minimum_required(VERSION 3.8)
project("pi-calc" VERSION 1.0)
find_package(Boost REQUIRED)
add_executable(pi-calc main.cpp)
target_link_libraries(pi-calc PRIVATE Boost::boost)
Note, in CMake versions 3.15 and later, you should instead use the Boost::headers target, which supersedes the Boost::boost target.
I'm using the package manager vcpkg to install the (static) Boost libraries via vcpkg install boost:x64-windows-static.
Furthermore, I use CMake as my build system and I'm passing C:\vcpkg\scripts\buildsystems\vcpkg.cmake to CMake via the -DCMAKE_TOOLCHAIN_FILE CMake command.
In my CMakeLists.txt I force static Boost libraries:
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost COMPONENTS filesystem iostreams REQUIRED)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
endif ()
# ...
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
However, Visual Studio still tries to look at the wrong file path for my Boost libraries:
Error 'C:/vcpkg/installed/x64-windows/lib/boost_filesystem-vc140-mt.lib', needed by 'MyProject.exe', missing and no known rule to make it
If I install the dynamic Boost libraries, it will build fine since this is where Visual Studio looks. However, I want to use the static libraries in my build instead so that all DLLs are "merged" into the final EXE.
How can I accomplish this?
I had the same problem.
Solved with
define set(Boost_INCLUDE_DIR "path")
before find_package force.
When you using cmake with vcpkg, find _VCPKG_INSTALLED_DIR variable in CmakeCache.txt
set(Boost_INCLUDE_DIR ${_VCPKG_INSTALLED_DIR}/x64-windows-static/include)
It seems that by default vcpkg.cmake script auto-detect dynamic libraries that are installed by vcpkg.
You can override this behavior for your project by setting a variable when invoking cmake:
cmake .. -DCMAKE_TOOLCHAIN_FILE=.../vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
Or using the CMakePresets.json:
"cacheVariables": {
...
"CMAKE_TOOLCHAIN_FILE": {
"value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"type": "FILEPATH"
},
"VCPKG_TARGET_TRIPLET": "x64-windows-static"
},
I haven't yet found how to do this on a per library basis.
More details here and here.
Actually, what I have found to work correctly is the following CMake:
# Boost settings
set(Boost_USE_STATIC_LIBS ON) # only find static libs
set(Boost_USE_DEBUG_LIBS OFF) # ignore debug libs and
set(Boost_USE_RELEASE_LIBS ON) # only find release libs
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON) # link Boost Static libraries
This question is one that has occurred before on SO. For instance this question:
Cmake doesn't find Boost
But the answers there and elsewhere don't seem to work.
On Ubuntu 16.04 with the stock boost 1.58.0 installed, I have also built, in a custom location, boost 1.68.0.
Now I am trying to compile a simple c++ program using boost, with cmake. It does not find boost. Either version (although 1.68.0 is the one I really want to use).
It gives:
-- Could NOT find Boost (missing: Boost_DIR)
The CMakeLists.txt file is below. CMake 3.12.1 is being used.
cmake_minimum_required(VERSION 3.0.0)
set(CMAKE_CXX_STANDARD 17)
project(mytest CXX)
set(Boost_DEBUG ON)
set(Boost_DETAILED_FAILURE_MSG ON)
set(BOOST_ROOT /home/hal/projects/boost/boost)
# set(Boost_DIR /home/hal/projects/boost/boost)
#set(Boost_USE_DEBUG_LIBS ON)
#set(Boost_USE_STATIC_LIBS ON)
#set(Boost_USE_MULTITHREADED ON)
# set(Boost_USE_STATIC_RUNTIME OFF)
#set(Boost_INCLUDE_DIR /home/hal/projects/boost/boost )
set(Boost_ADDITIONAL_VERSIONS "1.58" "1.58.0")
#set(BOOST_INCLUDEDIR /home/hal/projects/boost/boost/include )
#set(BOOST_LIBRARYDIR /home/hal/projects/boost/boost/lib )
#SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "/home/hal/projects/boost/boost")
#SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "/home/hal/projects/boost/boost/lib")
find_package(Boost 1.68.0 COMPONENTS system date_time PATHS /home/hal/projects/boost/boost )
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(mytest main.cpp)
target_link_libraries(mytest ${Boost_LIBRARIES} stdc++)
endif()
Unless you work with implementing of searching packaging, option PATHS for find_package is not such useful, just remove it:
find_package(Boost 1.68.0 COMPONENTS system date_time)
Explanations
There are two ways for search packages in CMake:
With XXXConfig.cmake script, shipped with a specific package installation. In this script all paths (libraries, include directories, etc.) are hardcoded.
With FindXXX.cmake script, shipped with CMake itself. This script searches the libraries and headers under the system directories (like /usr/local/lib) but also takes hints from the user.
By default, the second way is tried; only if FindXXX.cmake script is absent, the first way is used.
But some options for find_package are applied only for the first way, and PATHS is exactly an option of this sort: it specifies paths where XXXConfig.cmake file can be found. With such options, find_package uses the second way - it tries to find XXXConfig.cmake script and execute it. But it seems that your Boost installation lacks of this config script, so CMake fails to find Boost.
I successfully build my project on locale machine, but when i upload my build in Travis i see this:
CMake Error at /usr/share/cmake-3.2/Modules/FindBoost.cmake:1182
(message):
Unable to find the requested Boost libraries.
Boost version: 1.46.1
Boost include path: /usr/include
Could not find the following static Boost libraries:
boost_log
Some (but not all) of the required Boost libraries were found. You
may
need to install these additional Boost libraries. Alternatively,
set
BOOST_LIBRARYDIR to the directory containing Boost libraries or
BOOST_ROOT
to the location of Boost.
Call Stack (most recent call first):
CMakeLists.txt:18 (find_package)
-- Configuring incomplete, errors occurred!
I many time search this error in google, but i not found answer. My CMakeList file this:
cmake_minimum_required(VERSION 3.2)
project(Recast-server)
set(CMAKE_CXX_STANDARD 14)
file(GLOB_RECURSE SOURCE_FILES
"src/*.h"
"src/*.c"
"src/*.cpp")
include_directories(src/headers/)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
add_definitions(-DBOOST_LOG_DYN_LINK)
find_package(Boost 1.46 COMPONENTS system
thread
log
log_setup
program_options
filesystem
REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
add_executable(Recast-server ${SOURCE_FILES})
target_link_libraries(Recast-server ${Boost_LIBRARIES})
target_link_libraries(Recast-server ${CMAKE_THREAD_LIBS_INIT})
You can ask(or try commit) also in this PullRequest: https://github.com/bender-wardrobe/Recast/pull/15
Big Thanks for your answer <3
If I remember correctly Boost.Log was only added in later versions of Boost.
For earlier versions of Boost you can use the standalone Boost.Log from http://boost-log.sf.net
edit
You set the version 1.46 in your CMakeLists.txt. Maybe try a later version. Don't know about Travis.
I want to use Boosts support for command line flags in C++ on Linux. I use CMake to build the application, but I get a error "cannot find -lboost_program_options". The library boost_program_options was build independently using bjam, and the libraries are in the stage/lib subdirectory of the boost directory.
What does work: A solution is to add the stage/lib library using link_directories, but the CMake manual states:
Note that this command is rarely necessary. Library locations returned by find_package() and find_library() are absolute paths.
So that should not be nescessary.
What I want to have working:
Using find_package should be enough, but that doesn't work, here's the CMakeLists:
cmake_minimum_required(VERSION 3.6)
project(inp_manipulation)
set(CMAKE_CXX_STANDARD 11)
include_directories(includes lib/boost_1_62_0 lib/)
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "lib/boost_1_62_0")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "lib/boost_1_62_0/stage/lib")
find_package(Boost 1.62.0)
include_directories(${Boost_INCLUDE_DIR})
file(GLOB SOURCES *.cpp)
set(MAIN_FILE main.cpp)
set(SOURCE_FILES ${SOURCES})
add_executable(inp_manipulation ${MAIN_FILE} ${SOURCE_FILES} )
target_link_libraries(inp_manipulation -static-libgcc -static-libstdc++ boost_program_options)
Question
Where is the mistake in the CMakeLists?
Thanks in advance!
First, you must tell cmake that you require the specific component library from boost:
find_package(Boost 1.62.0 COMPONENTS program_options)
Second, always use the output variables from BoostFind.cmake
target_link_libraries(inp_manipulation -static-libgcc -static-libstdc++ ${Boost_LIBRARIES})
Documentation here: https://cmake.org/cmake/help/v3.0/module/FindBoost.html
Output variables are:
Boost_FOUND - True if headers and requested libraries were found
Boost_INCLUDE_DIRS - Boost include directories
Boost_LIBRARY_DIRS - Link directories for Boost libraries
Boost_LIBRARIES - Boost component libraries to be linked
etc