[C++-sig] Building with Scons

Nicolas Lara nicolaslara at gmail.com
Tue Jul 7 14:54:32 CEST 2009


Thanks for the reply,

Yes, I checked the name of the module. It matches the name of the
generated file. I also tried changing the name to include "lib" (since
scons also generates called libcylucene.so) but it doesnt work.
My module looks like this:

void init_util();

BOOST_PYTHON_MODULE(cylucene)
{
   init_util();
}

On Tue, Jul 7, 2009 at 2:53 AM, William Ladwig<wladwig at wdtinc.com> wrote:
> Does the name of the module defined in your BOOST_PYTHON_MODULE section match the name of the .so file (assuming you are using Linux)?  That's usually the error I get when I have a name mismatch.
>
> Also, I haven't really used scons, but shouldn't this:
>
> env.SharedLibrary(target='cylucene', source=FILES, SHLIBPREFIX='')
>
> be:
>
> env.SharedLibrary(target='cylucene', source=FILES, SHLIBPREFIX=''") ?
>
>
> Bill
>
>
> ________________________________________
> From: cplusplus-sig-bounces+wladwig=wdtinc.com at python.org [cplusplus-sig-bounces+wladwig=wdtinc.com at python.org] On Behalf Of Nicolas Lara [nicolaslara at gmail.com]
> Sent: Monday, July 06, 2009 6:25 PM
> To: Development of Python/C++ integration
> Subject: [C++-sig] Building with Scons
>
> Hello,
>
> I am trying to build a python extension with scons but the resulting
> library cannot be loaded:
>   ImportError: dynamic module does not define init function (initcylucene)
>
> I am using the following SConstruct file:
>
> FILES = ['typeconversion.cpp', 'document.cpp', 'search.cpp', 'queryparser.cpp',
>         'analysis.cpp', 'index.cpp', 'store.cpp', 'util.cpp']
> def python_tool(env):
>    pybase = 'python%s' % sys.version[0:3]
>    env.Append(CPPPATH=[os.path.join(sys.prefix, 'include', pybase)],
>               LIBPATH=[os.path.join(sys.prefix, 'lib', pybase, 'config')],
>               LIBS=['lib%s' % pybase])
>    if env['PLATFORM'] not in ['cygwin', 'win32']:
>        env.Append(LIBS=['util'])
>
> def boost_python_tool(env):
>    env.Append(CPPDEFINES=['BOOST_PYTHON_DYNAMIC_LIB',
>                           'BOOST_PYTHON_DYNAMIC_MODULE'],
>               CPPPATH=['$boostIncludes'],  # boostIncludes is a PathOption
>               LIBS=['boost_python'])
>
> def clucene_tool(env):
>    env.Append(CPPPATH=['/usr/local/lib/CLucene/',
>                        '/usr/local/lib/'],
>               LIBS=['clucene'])
>
> import os
> env = Environment(ENV=os.environ, tools=['default', python_tool,
>                                         boost_python_tool, clucene_tool])
> env.SharedLibrary(target='cylucene', source=FILES, SHLIBPREFIX='')
>
>
> Previously I was using the following Makefile, which worked but was
> statically linked:
>
> SHELL = /bin/bash
> SRC = ./src/
> BUILD = ./build/
> INCLUDES = -I/usr/include/python2.6/ -I/usr/local/lib/ -I/usr/local/lib/CLucene/
> LIBS = -lboost_python -lpython2.6 -lclucene
> CFLAGS = -shared -fPIC -g -pedantic -Wall -Wextra
> OBJECTS = document.o search.o queryparser.o analysis.o index.o store.o util.o
> LOBJECTS = $(BUILD)typeconversion.o $(BUILD)document.o
> $(BUILD)search.o $(BUILD)queryparser.o $(BUILD)analysis.o
> $(BUILD)index.o $(BUILD)store.o $(BUILD)util.o
>
> all: cylucene
>
> cylucene: $(OBJECTS)
>        mkdir -p $(BUILD) && cp $(SRC)initfile.py $(BUILD)__init__.py
>        $(CC) $(SRC)cylucene.cpp $(LOBJECTS) $(INCLUDES) $(LIBS) $(CFLAGS) -o
> $(BUILD)cylucene.so
>
> document.o: typeconversion.o
>        mkdir -p $(BUILD)
>        $(CC) $(SRC)document.cpp $(INCLUDES) $(LIBS) $(CFLAGS) -o $(BUILD)document.o
>
> queryparser.o: typeconversion.o
>        mkdir -p $(BUILD)
>        $(CC) $(SRC)queryparser.cpp $(INCLUDES) $(LIBS) $(CFLAGS) -o
> $(BUILD)queryparser.o
>
> analysis.o:
>        mkdir -p $(BUILD)
>        $(CC) $(SRC)analysis.cpp $(INCLUDES) $(LIBS) $(CFLAGS) -o $(BUILD)analysis.o
>
> search.o:
>        mkdir -p $(BUILD)
>        $(CC) $(SRC)search.cpp $(INCLUDES) $(LIBS) $(CFLAGS) -o $(BUILD)search.o
>
> index.o:
>        mkdir -p $(BUILD)
>        $(CC) $(SRC)index.cpp $(INCLUDES) $(LIBS) $(CFLAGS) -o $(BUILD)index.o
>
> store.o:
>        mkdir -p $(BUILD)
>        $(CC) $(SRC)store.cpp $(INCLUDES) $(LIBS) $(CFLAGS) -o $(BUILD)store.o
>
> util.o:
>        mkdir -p $(BUILD)
>        $(CC) $(SRC)util.cpp $(INCLUDES) $(LIBS) $(CFLAGS) -o $(BUILD)util.o
>
> typeconversion.o:
>        mkdir -p $(BUILD)
>        $(CC) $(SRC)typeconversion.cpp $(CFLAGS) -o $(BUILD)typeconversion.o
>
> clean:
>        rm -Rf build/
>
>
> Does anyone have experience working with scons and boost::python? Can
> anyone help?
>
> Thanks in advance!
>
>
> --
> Nicolas Lara
> Linux user #380134
> http://nicolas-lara.blogspot.com/
> Public key id: 0x152e7713 at http://subkeys.pgp.net/
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>



-- 
Nicolas Lara
Linux user #380134
http://nicolas-lara.blogspot.com/
Public key id: 0x152e7713 at http://subkeys.pgp.net/


More information about the Cplusplus-sig mailing list