Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-26-2010, 12:55 PM   #1
tank junior
Registered: Apr 2010
Posts: 42

Rep: Reputation: 0
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);

Old 12-02-2010, 07:09 PM   #2
Registered: Jun 2004
Location: Northern CA
Distribution: Debian
Posts: 835

Rep: Reputation: 49
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.)


gcc, python

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python Interpreter: load latest command? raskol Programming 6 04-10-2008 01:02 PM
howto build python with sqlite support? b3rx Slackware 4 12-03-2007 08:57 PM
python limits in the interpreter avallach Programming 3 07-30-2007 09:29 AM
Where is the Python Interpreter? Chomper Programming 8 01-15-2005 10:56 PM
Does Python interpreter have weird delay? lugoteehalt Programming 4 11-12-2003 02:43 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:44 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration