Are you sure you are doing it the correct way? The idea is that CMake sets BOOST_INCLUDE_DIR
, BOOST_LIBRARYDIR
and BOOST_ROOT
automatically. Do something like this in CMakeLists.txt
:
你确定你做这件事的方法正确吗?其思想是CMake自动设置BOOST_INCLUDE_DIR、BOOST_LIBRARYDIR和BOOST_ROOT。在CMakeLists.txt中执行以下操作:
FIND_PACKAGE(Boost)
IF (Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
ADD_DEFINITIONS( "-DHAS_BOOST" )
ENDIF()
If boost is not installed in a default location and can, thus, not be found by CMake, you can tell CMake where to look for boost like this:
如果Boost没有安装在默认位置,因此CMake找不到Boost,您可以这样告诉CMake在哪里查找Boost:
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:/win32libs/boost")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:/win32libs/boost/lib")
Of course, those two lines have to be before the FIND_PACKAGE(Boost)
in CMakeLists.txt
.
当然,这两行必须在CMakeLists.txt中的FIND_PACKAGE(Boost)之前。
There is more help available by reading the FindBoost.cmake
file itself. It is located in your 'Modules' directory.
阅读FindBoost.cmake文件本身可以获得更多帮助。它位于您的‘模块’目录中。
A good start is to set(Boost_DEBUG 1)
- this will spit out a good deal of information about where boost is looking, what it's looking for, and may help explain why it can't find it.
一个好的开始是设置(BOOST_DEBUG1)-这将显示大量有关Boost正在查找的位置、它正在查找的内容的信息,并可能有助于解释它找不到它的原因。
It can also help you to figure out if it is picking up on your BOOST_ROOT
properly.
它还可以帮助您确定它是否正确地拾取了您的BOOST_ROOT。
FindBoost.cmake
also sometimes has problems if the exact version of boost is not listed in the Available Versions variables. You can find more about this by reading FindBoost.cmake
.
如果Boost的确切版本没有列在可用版本变量中,FindBoost.cmake有时也会出现问题。你可以通过阅读FindBoost.cmake找到更多关于这方面的信息。
Lastly, FindBoost.cmake
has had some bugs in the past. One thing you might try is to take a newer version of FindBoost.cmake
out of the latest version of CMake, and stick it into your project folder alongside CMakeLists.txt
- then even if you have an old version of boost, it will use the new version of FindBoost.cmake
that is in your project's folder.
最后,FindBoost.cmake过去也有一些错误。你可以尝试的一件事是从最新版本的CMake中取出一个较新版本的FindBoost.cmake,并将其与CMakeLists.txt放在你的项目文件夹中--这样即使你有一个旧版本的Boost,它也会使用你项目文件夹中的新版本FindBoost.cmake。
Good luck.
祝好运。
For me this error was simply because boost wasn't installed so on ubuntu:
对我来说,这个错误很简单,因为在ubuntu上没有安装Boost:
sudo apt install build-essential libboost-system-dev libboost-thread-dev libboost-program-options-dev libboost-test-dev
Sudo apt安装内部版本-Essential libost-system-dev libost-线程-dev libost-Program-Options-dev libost-test-dev
I struggled with this problem for a while myself. It turned out that cmake
was looking for Boost library files using Boost's naming convention, in which the library name is a function of the compiler version used to build it. Our Boost libraries were built using GCC 4.9.1
, and that compiler version was in fact present on our system; however, GCC 4.4.7
also happened to be installed. As it happens, cmake's FindBoost.cmake
script was auto-detecting the GCC 4.4.7
installation instead of the GCC 4.9.1
one, and thus was looking for Boost library files with "gcc44
" in the file names, rather than "gcc49
".
我自己也为这个问题挣扎了一段时间。事实证明,cmake使用Boost的命名约定查找Boost库文件,其中库名称是用于构建它的编译器版本的函数。我们的Boost库是使用GCC 4.9.1构建的,该编译器版本实际上存在于我们的系统中;但是,碰巧也安装了GCC 4.4.7。碰巧的是,cmake的FindBoost.cmake脚本正在自动检测GCC 4.4.7安装,而不是GCC 4.9.1安装,因此正在查找文件名中包含“gcc44”而不是“gcc49”的Boost库文件。
The simple fix was to force cmake to assume that GCC 4.9 was present, by setting Boost_COMPILER
to "-gcc49
" in CMakeLists.txt
. With this change, FindBoost.cmake
looked for, and found, my Boost library files.
简单的修复方法是强制cmake假定存在GCC 4.9,方法是在CMakeLists.txt中将BOOST_COMPILER设置为“-gcc49”。通过此更改,FindBoost.cmake查找并找到了我的Boost库文件。
You can also specify the version of Boost that you would like CMake to use by passing -DBOOST_INCLUDEDIR
or -DBOOST_ROOT
pointing to the location of correct version boost headers
您还可以指定希望CMake使用的Boost版本,方法是将-DBOOST_INCLUDEDIR或-DBOST_ROOT传递到正确版本Boost标头的位置
Example:
示例:
cmake -DBOOST_ROOT=/opt/latestboost
Cmake-DBOOST_ROOT=/opt/LatestBoost
This will also be useful when multiple boost versions are on the same system.
当同一系统上有多个Boost版本时,这也很有用。
I also had a similar problem and discovered that the BOOST_INCLUDE_DIR, BOOST_LIBRARYDIR and BOOST_ROOT env variables must hold absolute paths.
HTH!
我也遇到了类似的问题,并且发现BOOST_INCLUDE_DIR、BOOST_LIBRARYDIR和BOOST_ROOT环境变量必须包含绝对路径。啊哈!
In my case Boost was not installed. I used below command on Mac and then cmake find_package(Boost) works like a charm
在我的情况下,没有安装Boost。我在Mac上使用了下面的命令,然后cmake find_Package(Boost)工作得很棒
brew install Boost
Please note upper case 'B' in Boost!
请注意Boost中的大写‘B’!
If you are building your own boost do not forget to use the --layout=versioned
otherwise the search for a particular version of library will fail
如果您正在构建自己的Boost,请不要忘记使用--layout=versioned,否则搜索特定版本的库将失败
For cmake version 3.1.0-rc2
to pick up boost 1.57
specify -D_boost_TEST_VERSIONS=1.57
对于cmake版本3.1.0-rc2,要获取Boost 1.57,请指定-D_BOOST_TEST_VERSIONS=1.57
cmake version 3.1.0-rc2
defaults to boost<=1.56.0
as is seen using -DBoost_DEBUG=ON
Cmake版本3.1.0-rc2默认为Boost<=1.56.0,如-DBoost_DEBUG=ON所示
cmake -D_boost_TEST_VERSIONS=1.57 -DBoost_DEBUG=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
Cmake-D_BOOST_TEST_VERSIONS=1.57-DBoost_DEBUG=ON-DCMAKE_BUILD_TYPE=DEBUG-DCMAKE_C_COMPILER=CLANG-DCMAKE_CXX_COMPILER=CLANG++
One more bit of advice for anyone trying to build CGAL in particular, with statically linked Boost. It is not enough to define Boost_USE_STATIC_LIBS
; it gets overridden by the time Boost_DEBUG
outputs its value. The thing to do here is to check the "Advanced" checkbox and to enable CGAL_Boost_USE_STATIC_LIBS
.
对于任何试图使用静态链接的Boost构建CGAL的人,还有一点建议。仅定义BOOST_USE_STATIC_LIBS是不够的;它会被BOOST_DEBUG输出值的时间覆盖。这里要做的是选中“高级”复选框并启用CGAL_BOOST_USE_STATIC_LIBS。
I had the same problem while trying to run make
for a project after installing Boost version 1.66.0 on Ubuntu Trusty64. The error message was similar to (not exactly like) this one:
在Ubuntu Truest64上安装Boost 1.66.0版后,我在尝试运行一个项目的make时遇到了同样的问题。该错误消息与以下消息类似(不完全相同):
CMake Error at
/usr/local/Cellar/cmake/3.3.2/share/cmake/Modules/FindBoost.cmake:1245 (message):
Unable to find the requested Boost libraries.
Boost version: 0.0.0
Boost include path: /usr/include
Detected version of Boost is too old. Requested version was 1.36 (or newer).
Call Stack (most recent call first):
CMakeLists.txt:10 (FIND_PACKAGE)
Boost was definitely installed, but CMake couldn't detect it. After spending plenty of time tinkering with paths and environmental variables, I eventually ended up checking cmake
itself for options and found the following:
Boost肯定是安装了,但CMake没有检测到。在花费大量时间修改路径和环境变量之后,我最终检查了cmake本身的选项,发现了以下内容:
--check-system-vars = Find problems with variable usage in system files
So I ran the following in the directory at issue:
因此,我在有问题的目录中运行了以下命令:
sudo cmake --check-system-vars
Sudo cmake--check-system-vars
which returned:
它返回了:
Also check system files when warning about unused and uninitialized variables.
-- Boost version: 1.66.0
-- Found the following Boost libraries:
-- system
-- filesystem
-- thread
-- date_time
-- chrono
-- regex
-- serialization
-- program_options
-- Found Git: /usr/bin/git
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/myproject
and resolved the issue.
并解决了这个问题。
See FindBoost.cmake
first. The variables you set are the correct ones but they should be all uppercase.
请先参阅FindBoost.cmake。您设置的变量是正确的,但它们应该全部大写。
Make sure the library architecture matches with CMake configuration.
确保库架构与CMake配置匹配。
cmake -A x64 ..
I suggest creating a minimal executable which only includes a Boost library to see if it compiles.
我建议创建一个最小的可执行文件,其中只包括一个Boost库,以查看它是否可以编译。
#include <iostream>
#include <boost/date_time.hpp>
int main() {
using namespace std;
using namespace boost::gregorian;
date today = day_clock::local_day();
cout << today << endl;
}
find_package(Boost REQUIRED COMPONENTS
date_time
)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIRS})
add_executable(test_boost "test_boost.cpp")
target_link_libraries(test_boost Boost::date_time)
Start debugging by checking Boost_FOUND
first.
首先检查BOOST_FOUND以开始调试。
message(STATUS "Boost_FOUND: ${Boost_FOUND}")
The version should be found even if no libraries are found. (Boost_VERSION
)
即使没有找到库,也应该找到该版本。(Boost_Version)
If Boost_LIBRARY_DIRS
becomes non-empty, it should compile.
如果BOOST_LIBRARY_DIRS变为非空,则应进行编译。
I had the same problem, and none of the above solutions worked. Actually, the file include/boost/version.hpp
could not be read (by the cmake script launched by jenkins).
我遇到了同样的问题,上面的解决方案都没有奏效。实际上,文件Include/Boost/version.hpp无法读取(由Jenkins启动的cmake脚本)。
I had to manually change the permission of the (boost) library (even though jenkins belongs to the group, but that is another problem linked to jenkins that I could not figure out):
我不得不手动更改(Boost)库的权限(尽管Jenkins属于该组,但这是另一个与Jenkins相关的问题,我无法解决):
chmod o+wx ${BOOST_ROOT} -R # allow reading/execution on the whole library
#chmod g+wx ${BOOST_ROOT} -R # this did not suffice, strangely, but it is another story I guess
This can also happen if CMAKE_FIND_ROOT_PATH
is set as different from BOOST_ROOT
.
I faced the same issue that in spite of setting BOOST_ROOT
, I was getting the error.
But for cross compiling for ARM I was using Toolchain-android.cmake in which I had (for some reason):
如果将CMAKE_FIND_ROOT_PATH设置为不同于BOOST_ROOT,也可能发生这种情况。我面临着同样的问题,尽管设置了BOOST_ROOT,我还是收到了错误。但对于ARM的交叉编译,我使用的是工具链-android.cmake,其中我(出于某种原因):
set(BOOST_ROOT "/home/.../boost")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${SYSROOT}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=${SYSROOT} -I${SYSROOT}/include/libcxx")
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS}")
set(CMAKE_FIND_ROOT_PATH "${SYSROOT}")
CMAKE_FIND_ROOT_PATH
seems to be overriding BOOST_ROOT
which was causing the issue.
CMAKE_FIND_ROOT_PATH似乎覆盖了导致该问题的BOOST_ROOT。
For those using python3.7
docker image, this solved:
对于使用python3.7 docker图像的用户,解决了以下问题:
apt install libboost-system-dev libboost-thread-dev
APT安装libost-system-dev libost-线程-dev
Maybe
也许吧
brew install boost
will help you.
会对你有所帮助。
更多回答
it doesnt work for me... It finds the boost library, but generate tons of errors at compilation time
对我不起作用..。它会找到Boost库,但在编译时会生成大量错误
Shouldn't it be 'BOOST_INCLUDEDIR
'?
不应该是‘BOOST_INCLUDEDIR’吗?
@IhorKaharlichenko, but BOOST_ROOT should be BOOST_ROOT. wonderful ! Let me try with all cases, camel case, all caps, with underscores, without underscores ... <face-palm>
@IhorKaharlichenko,但BOOST_ROOT应为BOOST_ROOT。太棒了!让我尝试所有大小写,驼峰大小写,全大写,带下划线,不带下划线...
@JoeyMallone, not that I came up with this wonderful and consistent approach. Address your complaints upstream :)
@JoeyMallone,并不是说我想出了这个奇妙而始终如一的方法。在上游解决您的投诉:)
I also needed to install libboost-filesystem-dev
我还需要安装libost-filessystem-dev
Thanks, that worked for me with Avro build for Windows.
谢谢,这对我使用Avro Build for Windows很有效。
Worked for me, setting it in the CMake GUI tool as a Environment... Then Add Entry, then BOOST_ROOT, value C:\Program Files\PCL 1.11.1\3rdParty\Boost (I have PCL Installed)
对我来说很有效,在CMake图形用户界面工具中将其设置为环境...然后添加条目,然后是BOOST_ROOT,值C:\Program Files\PCL 1.11.1\3rdParty\Boost(我已经安装了PCL)
Yes. Had the same problem because of the relative path in the BOOST_ROOT env. Many thanks to you!
是。由于BOOST_ROOT环境中的相对路径,也出现了同样的问题。非常感谢你!
我是一名优秀的程序员,十分优秀!