3

In maintaining old source at my new job, I'm trying to make things cleaner. In this instance, I've got a big project (1,001 source files) that depends very statically on python2.5. On my dev machine, I've got 2.6 installed, and I'm trying to get this project to include and link against >=2.5 and <3.0.

I see two issues at present. From a .c file:

#include <python2.5/Python.h>

And from the makefile

LDFLAGS = $(LIBS) -lusb-1.0 -lpthread -lSound -lsqlite3 -lm -lglib-2.0 -lpython2.5

So, my question is: how do I alter the .c file such that it uses the appropriate directory and how do I update the makefile so it links against the appropriate library?

EDIT: And while I'm at it, I suppose I could give glib-2.0 the same treatment.

4
  • Is using distutils, or another Python-aware build system, an option? In the case of Glib, you should be getting the compile and link flags from glib-config, I think. Commented Jul 24, 2012 at 19:21
  • After having read a ton more yesterday, I think the simplest solution will be to use the autotools. Commented Jul 25, 2012 at 14:32
  • The usual advice in the Python community is to extend, not embed, i.e. make this a Python program that calls into C rather than the other way around. If you do that, you can setuptools, but I imagine it may be a tough job rewriting a large program to work that way. Commented Jul 25, 2012 at 14:58
  • Quite so! This monstrous project has source dating from '91 riddled with goto statements and sparse (or non-existent) documentation. It's... well, suffice it to say I'm looking forward to having a hand in its rewriting with the aid of the other "new guy" here. Commented Jul 25, 2012 at 18:54

1 Answer 1

1

I would not change the C file, but the include path and LDFLAGS.

So the .C will have:

#include <Python.h>

And on the include path you add -I/path/to/python/2.5/include and -Lpython2.5

If you use a makefile, you can use the += to add options to the include path and library path.

LDFLAGS = $(LIBS) -lusb-1.0 -lpthread -lSound -lsqlite3 -lm
...
ifeq ($(PYTHON_VERSION),2.5)
    LDFLAGS += -lpython2.5
    CFLAGS += -I/path/to/python/2.5/include
else 
...
endif

Where PYTHON_VERSION is a variable you have to set.

Or if your paths are uniform:

LDFLAGS += -lpython$(PYTHON_VERSION)
CFLAGS += -I/path/to/python/$(PYTHON_VERSION)/include

If you use SCONS, it can be easier to script this kind of build using variant builds.

Do you have different source code for different versions of Python?

Or you just want to compile and link the same source code using different versions of Python?

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.