如何让 CMake 找到我的替代 Boost 安装?
我已在 /usr/local
中安装了最新版本的 Boost(包含在 /usr/local/include/boost
中,库在 /usr/local 中/lib/boost
),我现在尝试从源代码安装 Wt,但 CMake(版本 2.6)似乎找不到 Boost 安装。它试图提供有关设置 BOOST_DIR 和 Boost_LIBRARYDIR 的有用建议,但我无法通过调整这些变量来使其工作。
我收到的最新错误消息是它找不到库,但似乎表明它正在使用“/usr/local/include”作为包含路径,这是不正确的(我可以'似乎修复它)。他们是否有解决方案,或者我是否需要在 CMake 内部进行修改才能弄清楚?
I have installed the most recent version of Boost in /usr/local
(with includes in /usr/local/include/boost
and libraries in /usr/local/lib/boost
) and I am now attempting to install Wt from source, but CMake (version 2.6) can't seem to find the Boost installation. It tries to give helpful suggestions about setting BOOST_DIR and Boost_LIBRARYDIR, but I haven't been able to get it to work by tweaking these variables.
The most recent error message that I get is that it can't find the libraries, but it seems to indicate that it is using "/usr/local/include" for the include path, which isn't correct (and I can't seem to fix it). Is there a solution for this off the top of their head, or do I need to go mucking around inside CMake to figure it out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(16)
您应该查看 FindBoost.cmake 脚本,它处理 Boost 检测并设置所有 Boost 变量。它通常驻留在
/usr/share/cmake-2.6/Modules/
中。您将在其中找到文档。例如:与 BOOST_ROOT 相比,您引用的变量实际上是由 FindBoost 模块设置的变量。请注意,您不必(并且可能也不想)编辑 CMake 项目配置来设置 BOOST_ROOT。相反,您应该使用环境变量,例如调用
# BOOST_ROOT=/usr/local/... ccmake 。
You should have a look at
FindBoost.cmake
script, which handles Boost detection and setting up all Boost variables. It typically resides in/usr/share/cmake-2.6/Modules/
. In it, you will find documentation. For instance:In contrast to BOOST_ROOT, the variables you are referring to are actually variables that are set by the FindBoost module. Note that you don't have to (and probably also don't want to) edit your CMake project configuration to set BOOST_ROOT. Instead, you should use the environment variable, e.g. calling
# BOOST_ROOT=/usr/local/... ccmake .
我终于能够得到我想要的东西
I was finally able to get what I wanted with
简短版本
您只需要
BOOST_ROOT
,但如果您有多个安装或针对 iOS 或 Android 的交叉编译,您将需要禁用在系统中搜索本地 Boost。在这种情况下,addBoost_NO_SYSTEM_PATHS
设置为 false。通常,这是使用语法
-D=value
在 CMake 命令行上传递的。较长的版本
正式来说 FindBoost 页面指出这些变量应该是用于“暗示”Boost的位置。
这在理论上是正确的咒语:
当您从源代码编译时
然后,当您调用此脚本时,您需要包含 boost.cmake 脚本(我的脚本位于 a 子目录中),包含标头,指示依赖性并链接库。
The short version
You only need
BOOST_ROOT
, but you're going to want to disable searching the system for your local Boost if you have multiple installations or cross-compiling for iOS or Android. In which case addBoost_NO_SYSTEM_PATHS
is set to false.Normally this is passed on the CMake command-line using the syntax
-D<VAR>=value
.The longer version
Officially speaking the FindBoost page states these variables should be used to 'hint' the location of Boost.
This makes a theoretically correct incantation:
When you compile from source
Then when you call this script you'll need to include the boost.cmake script (mine is in the a subdirectory), include the headers, indicate the dependency, and link the libraries.
我遇到了类似的问题,CMake 仅找到供应商安装的 Boost,但我的集群有一个本地安装的版本,这正是我希望它使用的版本。 Red Hat Linux 6。
无论如何,看起来所有的
BOOSTROOT
、BOOST_ROOT
和Boost_DIR
内容都会让人烦恼,除非也设置Boost_NO_BOOST_CMAKE
(例如添加到命令行-DBoost_NO_BOOST_CMAKE=TRUE
)。(我承认 CMake 对于多平台很有用,但我仍然讨厌它。)
I had a similar issue, CMake finding a vendor-installed Boost only, but my cluster had a locally installed version which is what I wanted it to use. Red Hat Linux 6.
Anyway, it looks like all the
BOOSTROOT
,BOOST_ROOT
, andBoost_DIR
stuff would get annoyed unless one also setsBoost_NO_BOOST_CMAKE
(e.g add to cmd line-DBoost_NO_BOOST_CMAKE=TRUE
).(I will concede the usefulness of CMake for multiplatform, but I can still hate it.)
一般来说,最常见的错误是添加新选项后不清理构建目录。我从系统数据包管理器安装了 Boost。它的版本是1.49。
我还下载了 Boost 1.53 并将其“安装”在
$HOME/installs
下。我在项目中唯一要做的就是(我将源代码保存在
my_project_directory/src
中):就是这样。太棒了。
但如果我在
cd build
之后进行 ->cmake ../src
它将从系统路径设置Boost。然后执行cmake -DCMAKE_INCLUDE_PATH=$HOME/installs/include -DCMAKE_LIBRARY_PATH=$HOME/installs/lib ../src
不会改变任何内容。您必须清理构建目录(
cd build && rm -rf *
;))Generally the most common mistake is not cleaning your build directory after adding new options. I have Boost installed from system packet manager. Its version is 1.49.
I also downloaded Boost 1.53 and "installed" it under
$HOME/installs
.The only thing that I had to do in my project was to (I keep sources in
my_project_directory/src
):And that's it. Ta bum tss.
But if I'd make after
cd build
->cmake ../src
it would set Boost from the system path. Then doingcmake -DCMAKE_INCLUDE_PATH=$HOME/installs/include -DCMAKE_LIBRARY_PATH=$HOME/installs/lib ../src
would change nothing.You have to clean your build directory (
cd build && rm -rf *
;) )我遇到了类似的问题,我可以通过将以下行添加到我的
CMakeLists.txt
文件中来使用自定义的 Boost 库:I had a similar issue, and I could use customized Boost libraries by adding the below lines to my
CMakeLists.txt
file:有一种通用方法可以为 CMake 提供有关在何处查找库的指示。
查找库时,CMake 首先在以下变量中查找:
CMAKE_LIBRARY_PATH
和LD_LIBRARY_PATH
来查找库CMAKE_INCLUDE_PATH
和INCLUDE_PATH
如果您在其中一个环境变量中声明您的 Boost 文件,CMake 会找到它。示例:
如果太麻烦,您还可以使用我编写的一个不错的安装工具,它将为您完成所有操作:C++ 版本经理
There is a generic method to give CMake directions about where to find libraries.
When looking for a library, CMake looks first in the following variables:
CMAKE_LIBRARY_PATH
andLD_LIBRARY_PATH
for librariesCMAKE_INCLUDE_PATH
andINCLUDE_PATH
for includesIf you declare your Boost files in one of the environment variables, CMake will find it. Example:
If it's too cumbersome, you can also use a nice installing tool I wrote that will do everything for you: C++ version manager
在深入研究 CMake 并进行实验后,我确定 CMake 对我的所有 Boost 库都包含在
/usr/local/lib/boost
而不是/usr/local 中这一事实感到不满意/lib
.一旦我将它们软链接回来,构建就开始工作了。After digging around in CMake and experimenting, I determined that CMake was unhappy with the fact that all of my Boost libraries were contained in
/usr/local/lib/boost
and not/usr/local/lib
. Once I soft-linked them back out, the build worked.试试这个标志:
-DBoost_NO_BOOST_CMAKE=TRUE
。经过几个小时的尝试和修复,只有添加这个标志对我有用。我跑的是:
Try this flag:
-DBoost_NO_BOOST_CMAKE=TRUE
. After hours of trying and fixing, only adding this flag worked for me.What I ran was:
我花了大部分时间试图让这个工作正常进行。我尝试了所有的 -DBOOST_* &c。使用 CMake 的指令,但它一直链接到我的系统 Boost 库,即使在反复清除和重新配置我的构建区域之后也是如此。
最后,我修改了生成的 Makefile 并将 cmake_check_build_system 目标作废,不执行任何操作(如“echo ""”),这样当我运行 make 时它不会覆盖我的更改,然后执行“grep -rl "lboost_python" * | xargs sed -i "s:-lboost_python:-L/opt/sw/gcc5/usr/lib/ -lboost_python:g' 在我的 build/ 目录中显式地将所有构建命令指向我想要使用的 Boost 安装。最后,
我承认这是一个丑陋的拼凑,但我只是为了那些遇到同样的砖墙并且只想解决它的人的利益。完成工作。
I spent most of my evening trying to get this working. I tried all of the -DBOOST_* &c. directives with CMake, but it kept linking to my system Boost libraries, even after clearing and re-configuring my build area repeatedly.
At the end I modified the generated Makefile and voided the cmake_check_build_system target to do nothing (like 'echo ""') so that it wouldn't overwrite my changes when I ran make, and then did 'grep -rl "lboost_python" * | xargs sed -i "s:-lboost_python:-L/opt/sw/gcc5/usr/lib/ -lboost_python:g' in my build/ directory to explicitly point all the build commands to the Boost installation I wanted to use. Finally, that worked.
I acknowledge that it is an ugly kludge, but I am just putting it out here for the benefit of those who come up against the same brick wall, and just want to work around it and get work done.
在 CMake 中,您可以将以下内容添加到您的
CMakelists
中:此方法节省了我几个月的时间。你可以尝试一下。
顺便说一句,作为临时解决方案,您可以重命名您不希望找到的目录,如下所示:
希望它能帮助像我一样陷入困境的人。
In CMake, you can add the following to your
CMakelists
:This method saved my serveral months. you can try it.
By the way, as a temporary solution, you can rename directories you don't expect to find as below:
Hopefully, it will help people who are in deep trouble like me.
我在安装了两个版本的 Boost 的 Linux 服务器上遇到了类似的问题。一个是预编译的1.53.0版本,算作2018年的老版本;它位于
/usr/include
和/usr/lib64
中。我想要使用的版本是 1.67.0,因为我正在安装的另一个 C++ 库需要的最低版本为 1.65.1;它位于/opt/boost
中,其中包含include
和lib
子目录。正如之前答案中所建议的,我在CMakeLists.txt
中设置变量来指定在何处查找 Boost 1.67.0,如下所示,但 CMake 不接受这些更改。然后我在网上找到了一篇文章: CMake 可以使用local Boost,并意识到我需要更改
CMakeCache.txt
中的变量。在那里我发现与 Boost 相关的变量仍然指向默认的 Boost 1.53.0,所以难怪 CMake 不尊重我在CMakeLists.txt
中的更改。然后我在CMakeCache.txt
中设置了与 Boost 相关的变量,我还更改了指向 Boost 库的非标头、已编译部分的变量,以指向我想要的版本。然后CMake成功构建了依赖最新版本Boost的库。
I ran into a similar problem on a Linux server, where two versions of Boost have been installed. One is the precompiled 1.53.0 version which counts as old in 2018; it's in
/usr/include
and/usr/lib64
. The version I want to use is 1.67.0, as a minimum version of 1.65.1 is required for another C++ library I'm installing; it's in/opt/boost
, which hasinclude
andlib
subdirectories. As suggested in previous answers, I set variables inCMakeLists.txt
to specify where to look for Boost 1.67.0 as followsBut CMake doesn't honor those changes. Then I found an article online: CMake can use a local Boost, and realized that I need to change the variables in
CMakeCache.txt
. There I found that the Boost-related variables are still pointing to the default Boost 1.53.0, so no wonder CMake doesn't honor my changes inCMakeLists.txt
. Then I set the Boost-related variables inCMakeCache.txt
I also changed the variables pointing to the non-header, compiled parts of the Boost library to point to the version I want. Then CMake successfully built the library that depends on a recent version of Boost.
我也遇到了同样的问题,但不幸的是,尝试这里的提示并没有帮助。
唯一有帮助的是从 Boost 页面下载最新版本,编译并安装它
在 Ubuntu 上安装 Boost 1.50 中描述12.10。
就我而言,我使用的是 Boost 1.53。
I also encountered the same problem, but trying the hints here didn't help, unfortunately.
The only thing that helped was to download the newest version from the Boost page, compile and install it as
described in Installing Boost 1.50 on Ubuntu 12.10.
In my case I worked with Boost 1.53.
虽然 configure 可以找到我的 Boost 安装,但 CMake 却找不到。
找到 FindBoost.cmake 并查找 LIBRARY_HINTS 以查看它正在查找哪些子包。就我而言,它需要 MPI 和图形库。
apt-cache search ...我在构建代码时安装了开发包,并且开发包拖入了所有依赖项。我不太确定标准的 Boost 安装是否需要 Open MPI,但目前还可以。
While configure could find my Boost installation, CMake could not.
Locate FindBoost.cmake and look for LIBRARY_HINTS to see what sub-packages it is looking for. In my case it wanted the MPI and graph libraries.
apt-cache search ... I installed the dev packages since I was building code, and the dev package drags in all the dependencies. I'm not so sure that a standard Boost install needs Open MPI, but this is OK for now.
我刚刚添加了环境变量 Boost_INCLUDE_DIR 或将其添加到 cmake 命令 -DBoost_INCLUDE_DIR 并指向包含文件夹。
I just added the environment variable Boost_INCLUDE_DIR or add it to the cmake command -DBoost_INCLUDE_DIR and point to the include folder.
我也有同样的问题。
我的方法是通过环境变量定义要使用的版本(如果有):
I had the same problem.
My approach was to define which version to use (if any) via an environment variable: