Reputation: 4411
I've got a makefile, the makefile should create a number of shared object files. These file are going to be python modules. In the all target has the modules as dependencies. The swig wrappers (.cpp) fils are create as I would expect via the swig program, the .cpp are compiled as .o object files, however, the modules aren't created.
My makefile looks like:
CXXFLAGS :=$(CXXFLAGS) -fpic $(PYTHON3_CFLAGS)
LDLIBS :=$(LDLIBS) $(PYTHON3_LIBS)
SWIG=swig
SWIG_FLAGS:=-Wall -c++ -python #-DSWIG_TYPE_TABLE=fam #-external-runtime swigpyrun.h
IFACE_FILES += person.i
IFACE_FILES += parent.i
IFACE_FILES += child.i
WRAPPER_FILES = $(IFACE_FILES:.i=_wrap.cpp)
OBJS = $(WRAPPER_FILES:.cpp=.o)
MODULES = $(addprefix _, $(IFACE_FILES:.i=.so))
all:_person.so _child.so _parent.so #$(MODULES)
$(OBJS):$(WRAPPER_FILES)
$(MODULES):$(OBJS)
_%.so:%.cpp
$(CXX) -shared -o $@ $<
%_wrap.cpp:%.i
$(SWIG) $(SWIG_FLAGS) -o $@ $<
clean:
$(RM) $(WRAPPER_FILES)
$(RM) $(OBJS)
$(RM) $(MODULES)
When I run it I obtain:
$ make clean
rm -f person_wrap.cpp parent_wrap.cpp child_wrap.cpp
rm -f person_wrap.o parent_wrap.o child_wrap.o
rm -f _person.so _parent.so _child.so
$ make
swig -Wall -c++ -python -o person_wrap.cpp person.i
swig -Wall -c++ -python -o parent_wrap.cpp parent.i
swig -Wall -c++ -python -o child_wrap.cpp child.i
g++ -fpic `pkg-config --cflags python3` -c -o person_wrap.o person_wrap.cpp
g++ -fpic `pkg-config --cflags python3` -c -o parent_wrap.o parent_wrap.cpp
g++ -fpic `pkg-config --cflags python3` -c -o child_wrap.o child_wrap.cpp
$ make
make: Nothing to be done for 'all'.
So I must be doing something wrong, since the .so files aren't created/linked. But what am I missing?
Upvotes: 1
Views: 75
Reputation: 99094
You intend (I think) that the pipeline should run
person.i => person_wrap.cpp => person.o => _person.so
But look at these two rules:
$(MODULES):$(OBJS)
_%.so:%.cpp
$(CXX) -shared -o $@ $<
You ask for _person.so
, the second rule can build _person.so
from person.cpp
, but there is no person.cpp
and no way to build it. The first rule covers _person.so
, and has as its prerequisites person_wrap.o parent_wrap.o child_wrap.o
, which can be built, but it has no commands, so Make executes it-- and does nothing.
It's difficult to test, but I think eliminating your $(MODULES)
rule and making a slight modification:
_%.so:%_wrap.o
$(CXX) -shared -o $@ $<
will give you the effect you want.
Upvotes: 1
Reputation: 4006
You are trying to link your .so from your .cpp files, but you should link from your .o files:
_%.so: wrap_%.o
$(CXX) -shared -o $@ $<
Upvotes: 1