hi,python-chinese!
environment: FreeBSD4.11, gcc2.953.4, python2.2ports.
source code
#include Python.h
int main()
{
Py_Initialize();
PyRun_SimpleString(from time import time, ctime\n
print 'Today is', ctime( time() )\n);
Py_Finalize();
return 0;
}
document
5.6 Linking Requirements
While the configure script shipped with the Python sources will correctly build
Python to export the symbols needed by dynamically linked extensions, this is
not automatically inherited by applications which embed the Python library
statically, at least on Unix. This is an issue when the application is linked
to the static runtime library (libpython.a) and needs to load dynamic
extensions (implemented as .so files).
The problem is that some entry points are defined by the Python runtime solely
for extension modules to use. If the embedding application does not use any of
these entry points, some linkers will not include those entries in the symbol
table of the finished executable. Some additional options are needed to inform
the linker not to remove these symbols.
Determining the right options to use for any given platform can be quite
difficult, but fortunately the Python configuration already has those values.
To retrieve them from an installed Python interpreter, start an interactive
interpreter and have a short session like this:
import distutils.sysconfig
distutils.sysconfig.get_config_var('LINKFORSHARED')
'-Xlinker -export-dynamic'
The contents of the string presented will be the options that should be used.
If the string is empty, there's no need to add any additional options. The
LINKFORSHARED definition corresponds to the variable of the same name in
Python's top-level Makefile.
result when compile
[EMAIL PROTECTED] gcc34 test_python.cpp -o test_python
-L/usr/local/lib/python2.2/config -lpython2.2 -I/usr/local/include/python2.2
/usr/local/lib/python2.2/config/libpython2.2.a(posixmodule.o): In function
`posix_tmpnam':
posixmodule.o(.text+0x297a): warning: tmpnam() possibly used unsafely; consider
using mkstemp()
/usr/local/lib/python2.2/config/libpython2.2.a(posixmodule.o): In function
`posix_tempnam':
posixmodule.o(.text+0x28b6): warning: tempnam() possibly used unsafely;
consider using mkstemp()
/var/tmp//ccw3igF6.o(.eh_frame+0x11): undefined reference to
`__gxx_personality_v0'
/usr/local/lib/python2.2/config/libpython2.2.a(floatobject.o): In function
`float_rem':
floatobject.o(.text+0xf69): undefined reference to `fmod'
/usr/local/lib/python2.2/config/libpython2.2.a(floatobject.o): In function
`float_divmod':
floatobject.o(.text+0x): undefined reference to `fmod'
floatobject.o(.text+0x11a9): undefined reference to `floor'
/usr/local/lib/python2.2/config/libpython2.2.a(floatobject.o): In function
`float_pow':
floatobject.o(.text+0x13e2): undefined reference to `fmod'
floatobject.o(.text+0x14b5): undefined reference to `floor'
floatobject.o(.text+0x1541): undefined reference to `pow'
/usr/local/lib/python2.2/config/libpython2.2.a(bltinmodule.o): In function
`builtin_round':
bltinmodule.o(.text+0x1e1d): undefined reference to `floor'
bltinmodule.o(.text+0x1e37): undefined reference to `ceil'
/usr/local/lib/python2.2/config/libpython2.2.a(thread.o): In function
`PyThread_start_new_thread':
thread.o(.text+0x46): undefined reference to `pthread_attr_init'
thread.o(.text+0x57): undefined reference to `pthread_attr_setstacksize'
thread.o(.text+0x8b): undefined reference to `pthread_create'
thread.o(.text+0xa9): undefined reference to `pthread_attr_destroy'
thread.o(.text+0xbb): undefined reference to `pthread_detach'
/usr/local/lib/python2.2/config/libpython2.2.a(thread.o): In function
`PyThread_get_thread_ident':
thread.o(.text+0xe5): undefined reference to `pthread_self'
/usr/local/lib/python2.2/config/libpython2.2.a(thread.o): In function
`PyThread_allocate_lock':
thread.o(.text+0x198): undefined reference to `pthread_mutex_init'
thread.o(.text+0x1c2): undefined reference to `pthread_cond_init'
/usr/local/lib/python2.2/config/libpython2.2.a(thread.o): In function
`PyThread_free_lock':
thread.o(.text+0x20e): undefined reference to `pthread_mutex_destroy'
thread.o(.text+0x231): undefined reference to `pthread_cond_destroy'
/usr/local/lib/python2.2/config/libpython2.2.a(thread.o): In function
`PyThread_acquire_lock':
thread.o(.text+0x272): undefined reference to `pthread_mutex_lock'
thread.o(.text+0x2b6): undefined reference to `pthread_cond_wait'
thread.o(.text+0x2ec): undefined reference to `pthread_mutex_unlock'
/usr/local/lib/python2.2/config/libpython2.2.a(thread.o): In function
`PyThread_release_lock':
thread.o(.text+0x32e): undefined reference to `pthread_mutex_lock'
thread.o(.text+0x354): undefined reference to `pthread_mutex_unlock'
thread.o(.text+0x377): undefined reference to `pthread_cond_signal'
/usr/local/lib/python2.2/config/libpython2.2.a(thread.o): In function
`PyThread_allocate_sema':