-   Linux - Newbie (
-   -   Build ONLY python interpreter (

tank junior 10-26-2010 12:55 PM

Build ONLY python interpreter

I am using ubuntu hardy and python 2.6.5 (built from sources). For a custom python packager I need to rebuild python interpreter (python executable). I am new to linux and don't have much knowledge of gcc and other stuff. Here is the process:
1. Copy python.c as myapp.c. myapp.c is in the same directory (python2.6.5) in which I have all the required files.

2. Using the syntax from makefile of python sources, here is my first command to produce myapp.o


gcc -pthread -c -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -IInclude -I/home/zeno/installed/Python-2.6.5/Include -fPIC -DPy_BUILD_CORE -c myapp.c -o myapp.o
This produce myapp.o but throws a warning:

myapp.c:24:2: warning: no newline at end of file
Next is to produce the executable or python interpreter:

gcc -pthread -Xlinker -export-dynamic -o $@ myapp.o -L. -lpython2.6 -lpthread -ldl -lutil -lm -o myapp
This is causing an error:

/usr/lib/gcc/i486-linux-gnu/4.2.4/../../../../lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status

I am missing something in these two commands specially in the second one. I hope some one shed some light here:

BTW, here is myapp.c. It's a copy of python.c

/* Minimal main program -- everything is loaded from the library */

#include "Python.h"

#ifdef __FreeBSD__
#include <floatingpoint.h>

main(int argc, char **argv)
        /* 754 requires that FP exceptions run in "no stop" mode by default,
        * and until C vendors implement C99's ways to control FP exceptions,
        * Python requires non-stop mode.  Alas, some platforms enable FP
        * exceptions by default.  Here we disable them.
#ifdef __FreeBSD__
        fp_except_t m;

        m = fpgetmask();
        fpsetmask(m & ~FP_X_OFL);
        return Py_Main(argc, argv);



gd2shoe 12-02-2010 07:09 PM

Make sure you have build-essential installed. You may also need various -dev packages.

Generally, I'd recommend against using gcc directly on someone else's project. Usually "./" and "make test" suffice. It sounds like you might be using a tutorial somewhere. If so, it might help if you shared it.

Virtualenv is another tool that you might find interesting. It can be used to distribute the python interpreter, along with system and site packages. This eliminates many (but not all) system dependencies. It does eliminate any dependencies on the local python installation. (I haven't used it directly, but have relied on it as part of the script.)

All times are GMT -5. The time now is 10:00 AM.