Python论坛  - 讨论区

标题:[python-chinese] 关于在C程序中调用Python的问题

2006年10月18日 星期三 11:32

今晚打老虎 shrek.xu在gmail.com
星期三 十月 18 11:32:42 HKT 2006

´ó¼ÒºÃ£¬
ÎÒÔÚC³ÌÐòÖе÷ÓÃPythonµÄʱºòÓöµ½ÁËһЩÎÊÌâ¡£
*³ÌÐò´úÂ룺*
////////////////////////////////////////////////////////////////////////////////////

#include 
#include 
#include 
int main(int argc, char* argv[])
{
    Py_Initialize();
    PyRun_SimpleString("from time import time,ctime\n"
                       "print 'Today is',ctime(time())\n");
    Py_Finalize();

    return 0;
}
////////////////////////////////////////////////////////////////////////////////////

*±àÒëÃüÁ*
g++ -w -g -o testpy testpy.C -I/usr/local/include/python2.5
-L/usr/local/lib/python2.5/config -lpython2.5

*´íÎóÈçÏ£º*
/usr/local/lib/python2.5/config/libpython2.5.a(posixmodule.o)(.text+0x3c3e):
In function `posix_tmpnam':
Modules/posixmodule.c:6718: the use of `tmpnam_r' is dangerous, better use
`mkstemp'
/usr/local/lib/python2.5/config/libpython2.5.a(posixmodule.o)(.text+0x3bae):
In function `posix_tempnam':
Modules/posixmodule.c:6673: the use of `tempnam' is dangerous, better use
`mkstemp'
/usr/local/lib/python2.5/config/libpython2.5.a(dynload_shlib.o)(.text+0x176):
In function `_PyImport_GetDynLoadFunc':
Python/dynload_shlib.c:130: undefined reference to `dlopen'
/usr/local/lib/python2.5/config/libpython2.5.a(dynload_shlib.o)(.text+0x1b4):Python/dynload_shlib.c:141:
undefined reference to `dlsym'
/usr/local/lib/python2.5/config/libpython2.5.a(dynload_shlib.o)(.text+0x1c1):Python/dynload_shlib.c:133:
undefined reference to `dlerror'
/usr/local/lib/python2.5/config/libpython2.5.a(thread.o)(.text+0x19): In
function `PyThread_acquire_lock':
Python/thread_pthread.h:334: undefined reference to `sem_wait'
/usr/local/lib/python2.5/config/libpython2.5.a(thread.o)(.text+0x79):Python/thread_pthread.h:334:
undefined reference to `sem_trywait'
/usr/local/lib/python2.5/config/libpython2.5.a(thread.o)(.text+0xde): In
function `PyThread_start_new_thread':
Python/thread_pthread.h:171: undefined reference to
`pthread_attr_setstacksize'
/usr/local/lib/python2.5/config/libpython2.5.a(thread.o)(.text+0x100):Python/thread_pthread.h:181:
undefined reference to `pthread_create'
/usr/local/lib/python2.5/config/libpython2.5.a(thread.o)(.text+0x12b):Python/thread_pthread.h:197:
undefined reference to `pthread_detach'
/usr/local/lib/python2.5/config/libpython2.5.a(thread.o)(.text+0x1d9): In
function `PyThread_allocate_lock':
Python/thread_pthread.h:296: undefined reference to `sem_init'
/usr/local/lib/python2.5/config/libpython2.5.a(thread.o)(.text+0x22d): In
function `PyThread_free_lock':
Python/thread_pthread.h:320: undefined reference to `sem_destroy'
/usr/local/lib/python2.5/config/libpython2.5.a(thread.o)(.text+0x26a): In
function `PyThread_release_lock':
Python/thread_pthread.h:374: undefined reference to `sem_post'
/usr/local/lib/python2.5/config/libpython2.5.a(thread.o)(.text+0x2e5): In
function `PyThread_set_stacksize':
Python/thread_pthread.h:519: undefined reference to
`pthread_attr_setstacksize'
/usr/local/lib/python2.5/config/libpython2.5.a(thread.o)(.text+0x373): In
function `PyThread_delete_key':
Python/thread_pthread.h:374: undefined reference to `sem_post'
/usr/local/lib/python2.5/config/libpython2.5.a(thread.o)(.text+0x44f): In
function `PyThread_delete_key_value':
Python/thread_pthread.h:374: undefined reference to `sem_post'
/usr/local/lib/python2.5/config/libpython2.5.a(thread.o)(.text+0x52c): In
function `find_key':
Python/thread_pthread.h:374: undefined reference to `sem_post'
/usr/local/lib/python2.5/config/libpython2.5.a(posixmodule.o)(.text+0x1cd9):
In function `posix_openpty':
Modules/posixmodule.c:3386: undefined reference to `openpty'
/usr/local/lib/python2.5/config/libpython2.5.a(posixmodule.o)(.text+0x1d23):
In function `posix_forkpty':
Modules/posixmodule.c:3444: undefined reference to `forkpty'
СµÜ³õѧPython£¬»¹Çë´ó¼Ò°ïæ¡£
лл¡£
-- 
        "A good speech is like a good dress
         that's short enough to be interesting
         and long enough to cover the subject"

ÈÕÈÕÊǺÃÈÕ£¬Ê±Ê±ÊǺÃʱ¡£
http://www.nhacks.com/email/email/c2hyZWsueHU%3D/R01haWw%3D/0/image.png">

To the world,
      you are someone;
but to someone,
      you are the world.
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20061018/00b668ed/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年10月18日 星期三 11:44

Yingbo Qiu qiuyingbo在gmail.com
星期三 十月 18 11:44:26 HKT 2006

缺库,比如 -ldl -lpthread 你都没有加

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年10月18日 星期三 13:20

今晚打老虎 shrek.xu在gmail.com
星期三 十月 18 13:20:07 HKT 2006

ÄúºÃ£¬
ллÄãµÄ»Ø¸´¡£

ÎÒÓÖÊÔÁËһϣ¬»¹ÊÇÓÐЩÎÊÌâ¡£
ÄÜ·ñ¸øÄãÒ»¸öÀý×Ó£¿ÐèÒª¼ÓÄÄЩ¿âºÍ±àÒëÑ¡Ï

лл¡£

2006/10/18, Yingbo Qiu <qiuyingbo在gmail.com>:
>
> ȱ¿â£¬±ÈÈç -ldl -lpthread Ä㶼ûÓмÓ
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to   python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese




-- 
        "A good speech is like a good dress
         that's short enough to be interesting
         and long enough to cover the subject"

ÈÕÈÕÊǺÃÈÕ£¬Ê±Ê±ÊǺÃʱ¡£
http://www.nhacks.com/email/email/c2hyZWsueHU%3D/R01haWw%3D/0/image.png">

To the world,
      you are someone;
but to someone,
      you are the world.
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20061018/4ce4a4d3/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年10月18日 星期三 14:01

Yingbo Qiu qiuyingbo在gmail.com
星期三 十月 18 14:01:48 HKT 2006

你的问题其实和 python 本身无关. 你最好就近找一个资深的 Linux 程序员求助。我现在只看出少了 -ldl -lpthread -lutil


另外你用 g++ 而不是 gcc 也很奇怪.

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年10月18日 星期三 14:06

chuter liu topgun.chuter在gmail.com
星期三 十月 18 14:06:27 HKT 2006

>
> 要在编译器中设置,添加INCLUDE和LIB试试
> --
> ***********************************************
> 谨以赋予我们灵魂的四象之名宣誓,长流不息的自然的根源包含于其中。
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20061018/0c6452f9/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年10月18日 星期三 14:11

今晚打老虎 shrek.xu在gmail.com
星期三 十月 18 14:11:09 HKT 2006

лл´ó¼Ò£¬ÎÊÌâÒѾ­½â¾ö
¼Ó"-ldl -lpthread -lutil"ºóÎÊÌâ½â¾ö.

лл.

ÔÚ06-10-18£¬chuter liu <topgun.chuter在gmail.com> дµÀ£º
>
>  ÒªÔÚ±àÒëÆ÷ÖÐÉèÖã¬Ìí¼ÓINCLUDEºÍLIBÊÔÊÔ
> > --
> > ***********************************************
> > ½÷ÒÔ¸³ÓèÎÒÃÇÁé»êµÄËÄÏóÖ®ÃûÐûÊÄ£¬³¤Á÷²»Ï¢µÄ×ÔÈ»µÄ¸ùÔ´°üº¬ÓÚÆäÖС£
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>



-- 
        "A good speech is like a good dress
         that's short enough to be interesting
         and long enough to cover the subject"

ÈÕÈÕÊǺÃÈÕ£¬Ê±Ê±ÊǺÃʱ¡£
http://www.nhacks.com/email/email/c2hyZWsueHU%3D/R01haWw%3D/0/image.png">

To the world,
      you are someone;
but to someone,
      you are the world.
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20061018/6f31581e/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年10月18日 星期三 14:46

K.Ro roka100在gmail.com
星期三 十月 18 14:46:00 HKT 2006

我这里
gcc Pytest.c -o Pytest -I/usr/include/python2.4 -L/usr/lib/ -lpython2.4

就可以了

OS : Fedora Core 5

------------------------------
03:41:33::root在FC5::/home/Develop/python/C (5 files, 25k total)
#.:file Pytest
Pytest: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for
GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9,
not stripped
----------------------END----------------------
...For Development By K.Ro(Roka)...
03:44:25::root在FC5::/home/Develop/python/C (5 files, 25k total)
#.:ldd Pytest
        linux-gate.so.1 =>  (0xffffe000)
        libpython2.4.so.1.0 => /usr/lib/libpython2.4.so.1.0 (0x0558d000)
        libc.so.6 => /lib/libc.so.6 (0x0098e000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x00c23000)
        libdl.so.2 => /lib/libdl.so.2 (0x00aea000)
        libutil.so.1 => /lib/libutil.so.1 (0x0092f000)
        libm.so.6 => /lib/libm.so.6 (0x00ac3000)
        /lib/ld-linux.so.2 (0x00971000)
----------------------END----------------------
                                 ...For Development By K.Ro(Roka)...
03:44:32::root在FC5::/home/Develop/python/C (5 files, 25k total)
#.:./Pytest
Today is  Wed Oct 18 15:45:22 2006
----------------------END----------------------
-------------- 下一部分 --------------
一个HTML附件被移除...
URL: http://python.cn/pipermail/python-chinese/attachments/20061018/4c86912f/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号