Shared library from Boost python build does not contain any functions
Question: I'm having trouble building a shared library from my Boost Python project. For
some reason, the final shared library is nearly empty and doesn't contain any
of my wrapped functions. I've managed to get the "Hello World" example running
on my machine, so I'm pretty sure I've got Boost installed and configured
correctly.

Here is the module definition (in the FM.h header file):

    
    
    /* Python Wrapper using Boost.python */
    #include <boost/python.hpp>
    using namespace boost::python;
    
    BOOST_PYTHON_MODULE(fm_index)
    {
        class_<FM>("FM", init<>())
                .def(init<uint8_t* , uint32_t, uint32_t>())
                .def("save", &FM::save)
                .def("count", &FM::count)
                .def("locate", &FM::locate)
                .def("extract", &FM::extract)
                .def("load", &FM::load, return_value_policy<manage_new_object>())
                .staticmethod("load")
        ;
    }
    

And here is the build definition in my MakeFile:

    
    
    CCP=g++
    CFLAGS=-W -Wall -O3 -fPIC
    
    INCCDS=./libcds/includes/
    INCDIVSUF=./libdivsufsort/include/
    
    BOOST_INC=/home/adevabhaktuni/boost_1_52_0/
    BOOST_LIB=/home/adevabhaktuni/boost_1_52_0/stage/lib/
    
    PYTHON_VERSION=2.6
    PYTHON_INCLUDE=/usr/include/python$(PYTHON_VERSION)
    
    FM.o: FM.cpp FM.h
        $(CCP) -I $(INCCDS) -I $(INCDIVSUF) -I $(BOOST_INC) -I $(PYTHON_INCLUDE) -c $(CFLAGS) FM.cpp -o FM.o
    
    fm_index.so: FM.o ./libcds/lib/libcds.a ./libdivsufsort/lib/libdivsufsort.a
        $(CCP) -shared -W1,soname,fm_index.so -L $(BOOST_LIB) -lboost_python -lpython$(PYTHON_VERSION) FM.o ./libcds/lib/libcds.a ./libdivsufsort/lib/libdivsufsort.a -o fm_index.so
    

The object file FM.o is about 206 kB, and when I run nm -u on it I see all of
the functions I expect to see. However, the shared library fm_index.so is only
5 kB in size and is almost completely empty!

    
    
    nm -u fm_index.so
    
    fm_index.so:
    0000000000200540 a _DYNAMIC
    0000000000200728 a _GLOBAL_OFFSET_TABLE_
                 w _Jv_RegisterClasses
    0000000000200518 d __CTOR_END__
    0000000000200510 d __CTOR_LIST__
    0000000000200528 d __DTOR_END__
    0000000000200520 d __DTOR_LIST__
    0000000000000508 r __FRAME_END__
    0000000000200530 d __JCR_END__
    0000000000200530 d __JCR_LIST__
    0000000000200748 A __bss_start
                 w __cxa_finalize@@GLIBC_2.2.5
    00000000000004c0 t __do_global_ctors_aux
    0000000000000410 t __do_global_dtors_aux
    0000000000200538 d __dso_handle
                 w __gmon_start__
    0000000000200748 A _edata
    0000000000200758 A _end
    00000000000004f8 T _fini
    00000000000003b8 T _init
    00000000000003f0 t call_gmon_start
    0000000000200750 b completed.6145
    0000000000200748 b dtor_idx.6147
    0000000000000490 t frame_dummy
    

When I try to import the fm_index module in Python, I get the following error:

    
    
    ImportError: dynamic module does not define init function (initfm_index)
    

Does anyone know what is going on here? I'm not using bjam because I couldn't
figure out how to include the libcds.a and libdivsufsort.a libraries which the
fm_index module depends on. However, I used a similar MakeFile to the one
above on the "Hello World" project and it seemed to work fine. Any advice is
very appreciated!


Answer: You never define the functions you want to wrap with Boost.Python ?

Maybe you should take a look on the first hello world example in the
Boost.Python documentation:

[Exposing
Classes](http://www.boost.org/doc/libs/1_55_0/libs/python/doc/tutorial/doc/html/python/exposing.html)

