2

I am trying to compile some C wrapper functions to Python 3.4 using gcc and makefile, but I am having no success in finding the correct compile and link flags. I am using Ubuntu 14

Right now this is what I was trying in the makefile:

CC      = gcc
CFLAGS  = -Wall -std=c99 `pkg-config --cflags python3` 
LDFLAGS = `pkg-config --libs python3` 

final: functions.o wrapper.o
$(CC) -o functions.o $(CFLAGS) $(LDFLAGS)

functions.o: functions.c functions.h
$(CC) $(CFLAGS) -c functions.c

wrapper.o: wrapper.c
$(CC) $(CFLAGS) -g -c wrapper.c

Using this get me this error:

/usr/bin/ld: /usr/local/lib/libpython3.4m.a(dynload_shlib.o): undefined reference to symbol 'dlsym@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libdl.so.2: error adding symbols: DSO missing from command line

Also, I have little experience in makefiles, so I don't if I have done something wrong along the way

2
  • @MichaelPetch yes, got the same error Commented Nov 5, 2014 at 3:33
  • Building against the static library will not make you happy. Commented Nov 5, 2014 at 5:21

1 Answer 1

1

You should probably find a good tutorial on Makefiles, but this one should get you started:

CC      = gcc
CFLAGS  = -Wall -std=c99 `pkg-config --cflags python-3.4`
CFLAGS  += -fPIC
LDFLAGS = `pkg-config --libs python-3.4`

all: myfunctions.so

myfunctions.so: wrapper.o functions.o
    $(CC) -shared $(LDFLAGS) $^ -o $@

If you are creating C wrappers for Python you need to create a shared object. To do that at a minimum you have to use -fPIC when compiling and use -shared when linking. The sample Makefile above uses the built in rules to compile .c files into .o files. The shared object in this example will be created as myfunctions.so, but you can change myfunctions.so: to whatever you'd prefer to call it. This Makefile can be called with make all to generate the shared object.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.