CMAKE 3.9.3找不到Boost1.65.1 Boost_Python [英] CMAKE 3.9.3 Cannot Find Boost1.65.1 Boost_Python

查看:249
本文介绍了CMAKE 3.9.3找不到Boost1.65.1 Boost_Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在有点令人生畏.我已经尽我所能尝试了,但无济于事.

我正在使用基于Ubuntu 16.04 LTS的ElementaryOS Loki. 我在/usr/local下安装了boost 1.65.1 我正在使用cmake 3.9.3,该版本支持Build Boost 1.65.0及更高版本.

我已经尝试了各种可能的方法来弄乱我的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 "" )

来自命令行输出,我可以看到我正在将boost变量设置到正确的位置.

但是,cmake找不到boost_python.我真的不知道现在发生了什么.该行显示"BOOST FOUND"从未打印.

这也是完整的 make输出日志.

我使用python 3.6.2构建了boost,它也将用于构建boost_python,因此我可以对boost_python使用python 3.

有人撞过吗?

解决方案

感谢@JohnZwinck指出我所犯的明显的被忽略的错误,感谢@James分享了他的答案.但是他的答案似乎是Boost 1.63.0的答案,所以我想在这里发布解决方案,以便任何对最新CMAKE和Boost Python(直到今天)有疑问的人都可以节省一些抓头时间.

请先进行一些准备工作,所以请继续下载CMAKE 3.9.3,请注意,如果使用的是Boost 1.65.0或更高版本,则至少需要使用CMAKE 3.9.3,CMAKE明确捆绑了不同的Boost版本3.9.3是1.65.0或更高版本.

否则,您可能会从CMAKE说出错误

导入的目标不适用于增强版

安装Boost 1.65.1(使用python3.6.2)

下载Boost 1.65.1并将其提取到/usr/local

您可以按照Boost官方指南(入门指南)使用python2安装boost,它应该很轻松.

但是要使用python3安装boost,首先需要添加一个user-config.jam文件,并指定要用于构建Boost(增强Python)的python版本.您将需要像James一样(./bootstrap --with-python=Python3)在命令行上指定参数,并在主目录中添加user-config.jam.

首先,应在/home/$USERNAME/(/home的子目录)下创建一个user-config.jam.您可以指定您的编译器(gcc,clang等)和其他一些东西,对我们来说,它是python版本.

可以创建一个user-config.jam

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

在您的user-config.jam文件中,添加以下行:

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

替换为您的python 3版本.

现在我们正在构建和安装Boost 1.65.1

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

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

完成后,请确保您在.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"

设置CMAKELists.txt

问题细节中的一个很好用;但是,按照上述步骤操作后,下面的简单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 "" )

显然BOOST_FOUND消息是用于调试的,您可以放心地删除它.

现在您应该继续使用cmake& make.

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. 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.

I have tried every possible way to mess with my CMakeLists.txt, which as of now, looks like this

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. I really can't figure out what's going on now. the line says "BOOST FOUND" never got printed.

here is also the full cmake output log.

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.

Anyone has bumped into this before?

解决方案

Thanks @JohnZwinck for pointing out the obvious over-looked error I had and @James for sharing his answer. 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.

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.

Otherwise, you may get an error from CMAKE saying

imported targets not available for boost version

Install Boost 1.65.1 (with python3.6.2)

download Boost 1.65.1 and extract it under /usr/local

you can just follow Boost official guide (getting started guide) to install boost with python2, it should be hassle-free.

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). 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.

firstly, you should create a user-config.jam under your /home/$USERNAME/ (a subdirectory of /home). You can specify your compiler (gcc, clang, etc), and some other stuff, and for us it is the python version.

to create a user-config.jam, you can do

$ 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:

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

replace with your python 3 version.

now we are building and installing 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:

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

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.

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.

now you should just go ahead build using cmake & make.

这篇关于CMAKE 3.9.3找不到Boost1.65.1 Boost_Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆