简体   繁体   English

CMAKE 3.9.3无法找到Boost1.65.1 Boost_Python

[英]CMAKE 3.9.3 Cannot Find Boost1.65.1 Boost_Python

it's kind of very daunting now. 现在有点令人生畏。 I've tried all I could possibly figure out, to no avail. 我已经尝试了所有我可能想到的,无济于事。

I am using ElementaryOS Loki, based on Ubuntu 16.04 LTS. 我正在使用基于Ubuntu 16.04 LTS的ElementaryOS Loki。 I have boost 1.65.1 installed under /usr/local I am using cmake 3.9.3 which is supporting building boost 1.65.0 and forward. 我在/usr/local下安装了boost 1.65.1我正在使用cmake 3.9.3 ,它支持构建boost 1.65.0和forward。

I have tried every possible way to mess with my CMakeLists.txt , which as of now, looks like this 我已经尝试了一切可能的方法来搞乱我的CMakeLists.txt ,截至目前,它看起来像这样

cmake_minimum_required( VERSION 2.8 FATAL_ERROR )
project( boostpythondemo )

set( Boost_DEBUG ON )

MESSAGE("Boost Debugging is on.")

set( Boost_NO_SYSTEM_PATHS TRUE )

if( Boost_NO_SYSTEM_PATHS)
    set( BOOST_ROOT "/usr/local/boost_1_65_1" )
    set( BOOST_INCLUDEDIR "/usr/local/boost_1_65_1/boost" )
    set( BOOST_LIBRARYDIR "/usr/local/boost_1_65_1/stage/lib" )
endif( Boost_NO_SYSTEM_PATHS )


find_package( PythonLibs 3.6 REQUIRED )
include_directories( ${PYTHON_INCLUDE_DIRS} )

find_package( Boost COMPONENTS python REQUIRED )

if( Boost_FOUND )
       MESSAGE("******************************BOOST FOUND*******************")
endif( Boost_FOUND )

include_directories( ${Boost_INCLUDE_DIRS} )
link_directories( ${Boost_LIBRARIES} )

add_library( heyall SHARED heyall.cpp )

add_library( heyall_ext SHARED heyall_ext.cpp )
target_link_libraries( heyall_ext ${BOOST_LIBRARIES} heyall )
set_target_properties( heyall_ext PROPERTIES PREFIX "" )

from the command line output I can see I am setting the boost variables to the correct locations. 从命令行输出我可以看到我将增压变量设置到正确的位置。

However, cmake just can't find boost_python. 但是,cmake只是找不到boost_python。 I really can't figure out what's going on now. 我真的无法弄清楚现在发生了什么。 the line says "BOOST FOUND" never got printed. 该行说“BOOST FOUND”从未打印过。

here is also the full cmake output log . 这里也是完整的cmake输出日志

I built boost with python 3.6.2 which will be used to build boost_python as well, so this way I can use python 3 against boost_python. 我使用python 3.6.2构建了boost,它也将用于构建boost_python,所以我可以使用python 3来对抗boost_python。

Anyone has bumped into this before? 以前有人碰到过这个吗?

Thanks @JohnZwinck for pointing out the obvious over-looked error I had and @James for sharing his answer. 感谢@JohnZwinck指出我遇到的明显错误的错误和@James分享他的答案。 but it seems his answer is for Boost 1.63.0, so I wanted to post a solution here so anyone who's having problem with latest CMAKE and Boost Python (up to today) can save some head scratching time. 但似乎他的答案是Boost 1.63.0,所以我想在这里发布一个解决方案,所以任何遇到最新CMAKE和Boost Python问题的人(截至今天)都可以节省一些时间。

some prep work first, so go ahead download CMAKE 3.9.3, please beware that if you are using Boost 1.65.0 or above, you will need to use at least CMAKE 3.9.3, CMAKE explicitly bundles with different Boost versions and 3.9.3 is the one shipped with 1.65.0 or above. 首先要做一些准备工作,所以请继续下载CMAKE 3.9.3,请注意,如果你使用的是Boost 1.65.0或更高版本,你需要至少使用CMAKE 3.9.3,CMAKE明确捆绑不同的Boost版本和3.9。 3是1.65.0或以上附带的。

Otherwise, you may get an error from CMAKE saying 否则,您可能会收到来自CMAKE的错误说

imported targets not available for boost version 导入的目标不适用于升级版本

Install Boost 1.65.1 (with python3.6.2) 安装Boost 1.65.1(使用python3.6.2)

download Boost 1.65.1 and extract it under /usr/local 下载Boost 1.65.1并在/usr/local下解压缩

you can just follow Boost official guide (getting started guide) to install boost with python2, it should be hassle-free. 你可以按照Boost官方指南(入门指南)用python2安装boost,它应该没有麻烦。

but to install boost with python3, you will firstly need to add a user-config.jam file and specify the python version you want to use to build Boost (Boost Python). 但要使用python3安装boost,首先需要添加一个user-config.jam文件,并指定要用于构建Boost(Boost Python)的python版本。 You will need to specify the parameter on command line like James did ( ./bootstrap --with-python=Python3 ), and add an user-config.jam in your home directory. 您需要在命令行上指定参数,如James所做的( ./bootstrap --with-python=Python3 ),并在主目录中添加user-config.jam。

firstly, you should create a user-config.jam under your /home/$USERNAME/ (a subdirectory of /home ). 首先,您应该在/home/$USERNAME//home的子目录)下创建user-config.jam。 You can specify your compiler (gcc, clang, etc), and some other stuff, and for us it is the python version. 你可以指定你的编译器(gcc,clang等)和其他一些东西,对我们来说它是python版本。

to create a user-config.jam, you can do 要创建user-config.jam,你可以做到

$ sudo cp /usr/local/boost_1_65_1/tools/build/example/user-config.jam $HOME/user-config.jam

inside your user-config.jam file, add this line: 在你的user-config.jam文件中,添加以下行:

using python : 3.6 : /usr/bin/python3.6 : /usr/include/python3.6 : /usr/lib ;

replace with your python 3 version. 替换为您的python 3版本。

now we are building and installing Boost 1.65.1 现在我们正在构建和安装Boost 1.65.1

$ ./bootstrap.sh --prefix=/usr/local --with-python=python3

$ ./b2 --install -j 8 # build boost in parallel using all cores available

once it's finished make sure you in your .profile add: 一旦完成,请确保您在.profile添加:

export INCLUDE="/usr/local/include/boost:$INCLUDE"

export LIBRARY_PATH="/usr/local/lib:$LIBRARY_PATH"

export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"

Setting up CMAKELists.txt 设置CMAKELists.txt

The one in the question details works just fine; 问题细节中的那个工作得很好; but once you have followed the above steps, a simple CMAKELists.txt like below should suffice. 但是一旦你按照上面的步骤,一个简单的CMAKELists.txt就足够了。

cmake_minimum_required( VERSION 2.8 FATAL_ERROR )
project( boostpythondemo )     

find_package( PythonLibs 3.6 REQUIRED )
include_directories( ${PYTHON_INCLUDE_DIRS} )

find_package( Boost COMPONENTS python3 REQUIRED )

if( Boost_FOUND )
        MESSAGE("********************************FOUND BOOST***********************")
endif( Boost_FOUND )           

include_directories( ${Boost_INCLUDE_DIRS} )
link_directories( ${Boost_LIBRARIES} )

add_library( heyall SHARED heyall.cpp )

add_library( heyall_ext SHARED heyall_ext.cpp )
target_link_libraries( heyall_ext ${BOOST_LIBRARIES} heyall )
set_target_properties( heyall_ext PROPERTIES PREFIX "" )

Apparently the BOOST_FOUND message was for debugging you can safely remove it. 显然,BOOST_FOUND消息用于调试,您可以安全地删除它。

now you should just go ahead build using cmake & make . 现在你应该继续使用cmakemake构建。

There are some dependencies for both CMake and Boost, so I am removing my old answer and providing a link to the bash script on GitHubGist. CMake和Boost都有一些依赖关系,所以我删除了我的旧答案,并在GitHubGist上提供了bash脚本的链接。

The script can be found here 脚本可以在这里找到

To run the script first make it executable 要运行该脚本,请首先使其可执行

chmod +x boost_python3_install.sh

then run with sudo. 然后用sudo运行。

sudo ./boost_python3_install.sh

enjoy! 请享用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM