1

I have the following class called "Wav" which is stored in another directory, with the files "Wav.h" and "Wav.cpp" and looks like the following:

enum ReadType {
   NATIVE = 0,
   DOUBLE,
};

namespace AudioLib {
    class Wav : public Signal {
        public: 

           Wav(); 
           Wav(const int M, const int N);

           ///...  ->
    };
 };

The .cpp file contains the implementation of this class, everything compiles well.

I'm trying to implement a Python wrapper using boost.python and have the following file:

#include <boost/python.hpp>
#include "../src/Wav/Wav.h"

using namespace boost::python;

BOOST_PYTHON_MODULE(Wav)
{       
    class_<AudioLib::Wav>("Wav", 
          init<const int, const int>());
}

In my Makefile, I am compiling the Wav.cpp:

# Compile the .wav Python and Cpp file 
$(WAV_TARGET).so: $(WAV_TARGET).o
g++ -shared -Wl,--export-dynamic $(WAV_TARGET).o -L$(BOOST_LIB) -lboost_python -
    lboost_python -L/usr/lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION) -o 
    $(WAV_TARGET).so

$(WAV_TARGET).o: $(WAV_TARGET).cpp
g++ $(CFLAGS) ../src/Wav/Wav.cpp -I$(PYTHON_INCLUDE) -I$(BOOST_INC) -fPIC -c 
        $(WAV_TARGET).cpp 

And whenever I try to import into Python I get the following:

ImportError: Wav.so: undefined symbol: _ZN8AudioLib3WavC1Eii

Where am I going wrong?

1 Answer 1

1

It looks like you have failed to define the second constructor:

Wav(const int M, const int N);

I can replicate the error message by making a working (but simplified) copy of your example with in-line definitions and just removing the definition of that constructor. So my advice would be to check carefully for the definition in Wav.cpp and try creating an in-line definition to experiment.

If the definition does exist, maybe the linker flags are not right.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.