在Boost.Python的Bjam中包含系统库 [英] Including System Libraries with Bjam for Boost.Python

查看:93
本文介绍了在Boost.Python的Bjam中包含系统库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个非常基本的问题,但我无法在任何地方找到解决方案.我正在使用Boost.Python在C ++中构建Python扩展,并且需要将我的项目与libpcap链接,但是我指定的内容似乎都没有将bjam指向正确的位置. Pcap当前安装在/usr/local/include (OS X 10.9)中,我可以使用XCode,Make或任何其他构建系统将其导入.但是,当我尝试运行bjam时,出现链接器错误体系结构x86_64的未定义符号".

This is probably a really basic question but I haven't been able to find a solution anywhere. I'm building a Python extension in C++ using Boost.Python and need to link my project with libpcap, but nothing I specify seems to point bjam to the correct location. Pcap is currently installed to /usr/local/include (OS X 10.9) and I can import it with XCode, Make, or any other build system. However when I try to run bjam it gives me the linker error "Undefined symbols for architecture x86_64."

我通过将其他源文件添加到python-extension定义中来克服了第一轮链接器错误,但显然无法对外部库执行相同的操作.这是我的bjam文件(从其示例复制并稍作修改):

I got past the first round of linker errors by adding the other source files to the python-extension definition but obviously can't do the same for an external library. Here's my bjam file (copied from their example and slightly modified):

import python ;

if ! [ python.configured ]
{
    ECHO "notice: no Python configured in user-config.jam" ;
    ECHO "notice: will use default configuration" ;
    using python ;
}

use-project boost : ../../../Downloads/boost_1_55_0 ;

# Set up the project-wide requirements that everything uses the
# boost_python library from the project whose global ID is
# /boost/python.
project
  : requirements 
          <library>/boost/python//boost_python 
          <implicit-dependency>/boost//headers 
  : usage-requirements <implicit-dependency>/boost//headers 
  ;

python-extension pcap_ext : PacketWarrior/pcap_ext.cc PacketWarrior/PacketEngine.h PacketWarrior/PacketEngine.cc PacketWarrior/Packet.h ;

# Put the extension and Boost.Python DLL in the current directory, so
# that running script by hand works.
install convenient_copy 
  : pcap_ext
  : <install-dependencies>on <install-type>SHARED_LIB <install-type>PYTHON_EXTENSION 
    <location>. 
  ;

# A little "rule" (function) to clean up the syntax of declaring tests
# of these extension modules.
local rule run-test ( test-name : sources + )
{
    import testing ;
    testing.make-test run-pyd : $(sources) : : $(test-name) ;
}

# Declare test targets
run-test pcap : pcap_ext pcap.py ;

我确定它只是在项目要求中添加了一些内容,但是语法使我难以理解,我无法从[0]中找到的<libary>的任何变体似乎都起作用.我试图寻找将 llibpcap 标志传递给GCC的等效方法,但无济于事.任何指导,我们将不胜感激!

I'm sure it's just adding something to the project requirements, but the syntax eludes me and none of the variations of <libary> I could find from [0] seemed to work. I tried looking for equivalents of passing the llibpcap flag to GCC but to no avail. Any guidance is greatly appreciated!

[0]- https://wiki.python.org/moin/boost. python/BuildingExtensions

推荐答案

弄清楚了.当需要动态库时,我试图链接到标头路径.我将其添加到需求规则中,bjam能够正确地对其进行编译.

Figured it out. I was trying to link to the header paths when it needed the dynamic library. I added this to the requirements rule and bjam was able to compile it correctly.

<library>/usr/lib/libpcap.dylib

这篇关于在Boost.Python的Bjam中包含系统库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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