c++ - 为 Boost.Python 包含带有 Bjam 的系统库

标签 c++ boost-python bjam

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

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

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 ;

我确定它只是在项目要求中添加了一些内容,但语法让我难以理解,而且 <libary> 的任何变体都没有。我可以从 [0] 中找到似乎有效。我尝试寻找将 llibpcap 标志传递给 GCC 的等价物,但无济于事。非常感谢任何指导!

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

最佳答案

想通了。当它需要动态库时,我试图链接到标题路径。我将其添加到需求规则中,bjam 能够正确编译它。

<library>/usr/lib/libpcap.dylib

关于c++ - 为 Boost.Python 包含带有 Bjam 的系统库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20322027/

相关文章:

c++ - IcmpSendEcho 失败但 "ping"成功

c++ - 链接问题 Boost.Python

c++ - Boost bjam 不会将编译器版本放在文件名中

c++ - "const int const &someval"中的第二个 const 在做什么?

C++ 删除或覆盖文件中的现有信息

c++ - 在boost python中用map_indexing_suite包装一个string/shared_ptr unordered_map

c++ - 用 Boost.Python 包装 Eigen 的 operator()() 时的重载分辨率

cross-platform - 从 Jam 迁移到 CMake

c++ - 当我安装了多个 Visual Studio 版本时,如何使用 Visual Studio 2008 构建 boost?

c++ - 二叉搜索树中序遍历递归函数不能正常工作