Problem with linking embedding C application

Mads Bondo Dydensborg madsdyd at challenge.dk
Mon Oct 1 13:16:58 CEST 2001


On Mon, 1 Oct 2001, Olivier Deme wrote:

> Hi,
> 
> We have written an application written in C, which invokes sometimes the Python 
> interpreter for executing Python methods.
> 
> So, I am trying to statically link our application with libpython*.*.a., but this result in various 
> undefined symbols (see below).
> 
> Now, it looks like I am missing symbols defined in the math and posix
> thread library! I don't understand this since we are not using any
> symbols defined in these libraries.

No, but the statically linked python lib is.

> Could anybody tell me what is going on and how I can fix this problem?

I am having similar troubles, although mine is trying to identify these
libs automatically. (Using autoconf - you replied to this thread, I can
see.)
> 
> /lib/libpython.a(posixmodule.o): In function `posix_tmpnam':
> /home/odeme/Python-2.1.1/./Modules/posixmodule.c:4212: the use of `tmpnam_r' is dangerous, better use `mkstemp'
> /lib/libpython.a(posixmodule.o): In function `posix_tempnam':
> /home/odeme/Python-2.1.1/./Modules/posixmodule.c:4168: the use of `tempnam' is dangerous, better use `mkstemp'

These are just (annoying) warnings from stuff used in the belly of
python.

> /lib/libpython.a(floatobject.o): In function `float_pow':
> /home/odeme/Python-2.1.1/Objects/floatobject.c:532: undefined reference to `pow'
> /lib/libpython.a(dynload_shlib.o): In function `_PyImport_GetDynLoadFunc':
> /home/odeme/Python-2.1.1/Python/dynload_shlib.c:86: undefined reference to `dlopen'
> /home/odeme/Python-2.1.1/Python/dynload_shlib.c:94: undefined reference to `dlerror'
> /home/odeme/Python-2.1.1/Python/dynload_shlib.c:99: undefined reference to `dlsym'
> /lib/libpython.a(thread.o): In function `PyThread_start_new_thread':
> /home/odeme/Python-2.1.1/Python/thread_pthread.h:135: undefined reference to `pthread_create'
> /home/odeme/Python-2.1.1/Python/thread_pthread.h:159: undefined reference to `pthread_detach'
> /lib/libpython.a(posixmodule.o): In function `posix_openpty':
> /home/odeme/Python-2.1.1/./Modules/posixmodule.c:1754: undefined reference to `openpty'
> /lib/libpython.a(posixmodule.o): In function `posix_forkpty':
> /home/odeme/Python-2.1.1/./Modules/posixmodule.c:1785: undefined reference to `forkpty'
> /lib/libpython.a(complexobject.o): In function `_Py_c_pow':
> /home/odeme/Python-2.1.1/Objects/complexobject.c:139: undefined reference to `pow'
> /home/odeme/Python-2.1.1/Objects/complexobject.c:143: undefined reference to `exp'
> /home/odeme/Python-2.1.1/Objects/complexobject.c:144: undefined reference to `log'
> /home/odeme/Python-2.1.1/Objects/complexobject.c:146: undefined reference to `cos'
> /home/odeme/Python-2.1.1/Objects/complexobject.c:147: undefined reference to `sin'
> collect2: ld returned 1 exit status

I think that you may need to add at least
-lpthread -lm -lutil 
to you ld line?

I have a machine, where I need to do:
 -lnsl -ldl -lreadline -ltermcap -lpthread -lutil -lm
to be able to link with python.

The annoying thing is, that it is very hard to determine this in
general. At least I am not aware of any way to do it.

Mads

-- 
Mads Bondo Dydensborg.                               madsdyd at challenge.dk
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/J d- s+:+ a- C++ UL++++ P++ L++> E(++) W+ N w-- X- !tv b+ DI++ e++> h--
------END GEEK CODE BLOCK------






More information about the Python-list mailing list