467,146 Members | 1,240 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,146 developers. It's quick & easy.

statically linked python

Hi:

I have searched the docs and google but have not totally figured
out how to accomplish my task: On a linux box, I want to compile
and link python so that it uses no shared libraries, but does support
import of some "extra" modules. I have made a few attempts but
with limited success. In particular, I have tried things like
adding -static to the compiler options in the Makefile.

At one point I managed to build a python that was close to what I
wanted, e.g. when I ran "ldd python", it said:
not a dynamic executable
In that version, when I do some imports, e.g. sys, os, etc. they
load fine. But, when I try to import some other modules, e.g. time,
they are not found. I have tried similar procedures while also
altering Modules/Setup.local (produced by configure) to contain:
time timemodule.c # -lm # time operations and variables

There has to be a simple, "elegant" way to accomplish this which I am
simply overlooking. Any help would be appreciated.

Thanks.
--ralph
Jun 17 '06 #1
  • viewed: 2157
Share:
3 Replies
Ralph Butler wrote:
Hi:

I have searched the docs and google but have not totally figured
out how to accomplish my task: On a linux box, I want to compile
and link python so that it uses no shared libraries, but does support
import of some "extra" modules. I have made a few attempts but
with limited success. In particular, I have tried things like
adding -static to the compiler options in the Makefile.

At one point I managed to build a python that was close to what I
wanted, e.g. when I ran "ldd python", it said:
not a dynamic executable
In that version, when I do some imports, e.g. sys, os, etc. they
load fine. But, when I try to import some other modules, e.g. time,
they are not found. I have tried similar procedures while also
altering Modules/Setup.local (produced by configure) to contain:
time timemodule.c # -lm # time operations and variables

There has to be a simple, "elegant" way to accomplish this which I am
simply overlooking. Any help would be appreciated.


This has nothing to do with python. glibc doesn't support loading
shared libraries into statically linked executables. At least it didn't
support in 2002:
http://www.cygwin.com/ml/libc-alpha/.../msg00079.html
Since it still doesn't work most likely it is still not supported, but
you may ask glibc developers what is the problem.

Jun 17 '06 #2
Serge Orlov wrote:
Ralph Butler wrote:
Hi:

I have searched the docs and google but have not totally figured
out how to accomplish my task: On a linux box, I want to compile
and link python so that it uses no shared libraries, but does support
import of some "extra" modules. I have made a few attempts but
with limited success. In particular, I have tried things like
adding -static to the compiler options in the Makefile.

At one point I managed to build a python that was close to what I
wanted, e.g. when I ran "ldd python", it said:
not a dynamic executable
In that version, when I do some imports, e.g. sys, os, etc. they
load fine. But, when I try to import some other modules, e.g. time,
they are not found. I have tried similar procedures while also
altering Modules/Setup.local (produced by configure) to contain:
time timemodule.c # -lm # time operations and variables

There has to be a simple, "elegant" way to accomplish this which I am
simply overlooking. Any help would be appreciated.


This has nothing to do with python. glibc doesn't support loading
shared libraries into statically linked executables. At least it didn't
support in 2002:
http://www.cygwin.com/ml/libc-alpha/.../msg00079.html
Since it still doesn't work most likely it is still not supported, but
you may ask glibc developers what is the problem.


I do not want to load them. I want to statically link the code for a
module (e.g. time) directly into the statically linked executable.
Sorry if that was not clear.
Jun 18 '06 #3
Ralph Butler wrote:
Serge Orlov wrote:
Ralph Butler wrote:
Hi:

I have searched the docs and google but have not totally figured
out how to accomplish my task: On a linux box, I want to compile
and link python so that it uses no shared libraries, but does support
import of some "extra" modules. I have made a few attempts but
with limited success. In particular, I have tried things like
adding -static to the compiler options in the Makefile.

At one point I managed to build a python that was close to what I
wanted, e.g. when I ran "ldd python", it said:
not a dynamic executable
In that version, when I do some imports, e.g. sys, os, etc. they
load fine. But, when I try to import some other modules, e.g. time,
they are not found. I have tried similar procedures while also
altering Modules/Setup.local (produced by configure) to contain:
time timemodule.c # -lm # time operations and variables

There has to be a simple, "elegant" way to accomplish this which I am
simply overlooking. Any help would be appreciated.


This has nothing to do with python. glibc doesn't support loading
shared libraries into statically linked executables. At least it didn't
support in 2002:
http://www.cygwin.com/ml/libc-alpha/.../msg00079.html
Since it still doesn't work most likely it is still not supported, but
you may ask glibc developers what is the problem.


I do not want to load them. I want to statically link the code for a
module (e.g. time) directly into the statically linked executable.
Sorry if that was not clear.


OK, so you're asking how to make a module builtin. I haven't done that
myself, but let me give you a hint where to look: there is list of
builtin modules sys.builtin_module_names if you search the whole python
source distribution for some of the names in the list you'll get list
of files where to look. I've just searched and found that only two
files are involved: PC\config.c and setup.py

Jun 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by arve.knudsen@gmail.com | last post: by
1 post views Thread by David Douthitt | last post: by
reply views Thread by Frank Duan via .NET 247 | last post: by
reply views Thread by John Murtari | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.