【问题标题】:boost python fails to create extension dllboost python无法创建扩展dll
【发布时间】:2013-12-04 21:32:38
【问题描述】:

我正在尝试编译 boost python tutorial 文件。发生了什么是运行 bjam 我在 bin/msvc-11.0/debug 目录中创建了以下文件:

hello.obj、hello.obj.rsp、hello_ext.exp、hello_ext.lib、hello_ext.pdb、hello_ext.pyd、hello_ext.pdb.manifest、hello_ext.pyd.rsp。

但没有创建 dll。如果我运行 hello.py,我会得到:

导入错误:DLL 加载失败。找不到特定模块。

为什么 bjam 不构建 dll?

【问题讨论】:

  • bjam 对于构建系统 imo 来说是一个糟糕的选择。您可以找到有关如何使用例如 scons 来构建 boost python 扩展的教程。这就是我所做的。这不能回答你的问题,我知道。如果您对如何执行此操作的更多详细信息感兴趣,请告诉我,我会添加一些内容,尽管网上有示例。
  • 是的,我已经找到了一些提到 scons 的文章。我会检查一下。但如果你能在这里举个例子,我会很感激。

标签: c++ python boost dll


【解决方案1】:

以下文件逐字逐句来自我的一个项目,应该会给您一个想法。 请注意,它会尝试查找要链接的 Python 的默认版本。可能有更好的方法来做到这一点。 如果有不清楚的地方,请随时在 cmets 中提问。 使用此 SConstruct 构建的 Boost Python 模块称为 genocpp。如果您克隆,您应该能够构建它 项目代码,假设您使用的是 Linux。使用 Windows 会更加困难。

您还可以在 https://bitbucket.org/faheem/snppy/src/tip/SConstruct?at=default 在线找到此文件,作为 SNPPy 项目代码的一部分。

#!/usr/bin/python

import commands, glob, os

# Common file, for both executables and Python Interface
common_files = """geno print"""

def pyversion():
        pystr = commands.getoutput('python -V')
        version = pystr.split(' ')[1]
        major, minor = version.split('.')[:2]
        return major + '.' + minor

common_base = Split(common_files)
common = [f + ".cpp" for f in common_base]
common_obj = [f+".o" for f in common_base]

# For Python interface only
pif_conv = Split("cppvec_conv cppmap_conv cppset_conv cppunicode_conv")
pif_conv_files = [t+"_pif.cpp" for t in pif_conv]
pif = Split("geno")
pif_files = [t+"_pif.cpp" for t in pif]

# Boost Python Environment
boost_python_env = Environment(
    #CXX="g++-4.4",
    CPPPATH=["/usr/include/python"+pyversion(), "."],
    CXXFLAGS='-ftemplate-depth-100 -fPIC -Wall -Werror -pedantic -pipe -O3 -ffast-math -march=opteron',
    CPPDEFINES=['BOOST_PYTHON_DYNAMIC_LIB'],
    LIBPATH=["/usr/lib/python"+pyversion()+"/config"],
    LIBS=["python"+pyversion(), "m", "boost_python"],
    SHLIBPREFIX="", #gets rid of lib prefix
    SHOBJSUFFIX = ".bpo"
    )

test_env = Environment(
    #CXX="g++-4.4",
    CXXFLAGS='-Wall -Werror -pedantic -O0 -g',
    )

# Build boost python module
boost_python_env.SharedLibrary(target='genocpp', source = common + pif_conv_files + pif_files)
test_env.Program(target='geno_test', source = common + ["geno_test.cpp"])

【讨论】:

  • 我会看看它,虽然我在 windows 上。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-02-27
  • 2017-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多