Search code examples
c++makefilepybind11

undefined symbol: PyInstanceMethod_Type when trying to import pybind into a makefile c++ project


I am using pybind11 in my makefile. I added all the header files to my project for pybind11. I am getting the error:

Error /home/vagrant/ss/bt/strategies_dlls/PybindStrategy.so: undefined symbol: PyInstanceMethod_Type

What am I doing wrong? I am compiling into a .so file that is used in another project.

Here is a portion of my makefile

INCLUDES=-I/usr/include -I/usr/include/python3.8 -I$(INCLUDEPATH)
LDFLAGS=$(LIBPATH)/libstrategystudio_analytics.a $(LIBPATH)/libstrategystudio.a $(LIBPATH)/libstrategystudio_transport.a $(LIBPATH)/libstrategystudio_marketmodels.a $(LIBPATH)/libstrategystudio_utilities.a $(LIBPATH)/libstrategystudio_flashprotocol.a
LIBRARY=PybindStrategy.so

SOURCES=PybindStrat.cpp
HEADERS=PybindStrat.h
 
OBJECTS=$(SOURCES:.cpp=.o)

all: $(HEADERS) $(LIBRARY)

$(LIBRARY) : $(OBJECTS)
    $(CC) -shared -Wl,-soname,$(LIBRARY).1 -o $(LIBRARY) $(OBJECTS) $(LDFLAGS)

Solution

  • I was able to fix this by adding -lpython3.8 to my ld flags in the makefile