0
votes

I am trying to compile boost python tutorial files.What happens is that running bjam I am getting the following files created in bin/msvc-11.0/debug directory:

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.

But no dll created.If I run hello.py I am getting :

Import Error:DLL load failed.The specific module could not be found.

Why bjam doesn't build the dll ?

1
bjam is a terrible choice for a build system imo. You can find tutorials on how to use for example scons to build boost python extensions. This is what I do. This doesn't answer your question, I know. If you are interested in more details on how to do this, let me know and I'll add something, though there are examples online.Faheem Mitha
Yeah,I already found some articles mentioning scons.I will check it.But if you could put here an example how it can be done with it I will appreciate.Michael IV

1 Answers

0
votes

The following file is verbatim from one of my projects, and should give you an idea. Notice it tries to find the default version of Python to link against. There might be better ways of doing this. Feel free to ask questions in comments if something is not clear. The Boost Python module that is built with this SConstruct is called genocpp. You should be able to build it if you clone the project code, assuming you are using Linux. With Windows it will be more difficult.

You can also find this file online at https://bitbucket.org/faheem/snppy/src/tip/SConstruct?at=default as part of the SNPPy project code.

#!/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"])