Python论坛  - 讨论区

标题:[python-chinese] embed python interpreter in c -- help

2006年01月16日 星期一 16:22

nicran nicran at gmail.com
Mon Jan 16 16:22:14 HKT 2006

大家好,我在跑下面的例子的时候,得到如下错误,请各位给个线索,怎么解决。多谢了


/Temp/ccqv0PBa.o(.text+0x1f):my.c: undefined reference to `_Py_Initialize'
/Temp/ccqv0PBa.o(.text+0x2b):my.c: undefined reference to
`_PyRun_SimpleString'
/Temp/ccqv0PBa.o(.text+0x37):my.c: undefined reference to
`_PyRun_SimpleString'
/Temp/ccqv0PBa.o(.text+0x3c):my.c: undefined reference to `_Py_Finalize'
collect2: ld returned 1 exit status


---- my command ----
gcc temp.c -I/usr/include/python2.4

---- temp.c -----
#include 
#include 
int main(int argc, char * argv[])
{
  // initialize the interpreter
  Py_Initialize();
  // evaluate some code
  PyRun_SimpleString("import sys\n");
  //ignore line wrap on following line
  PyRun_SimpleString("sys.stdout.write('Hello from an embedded Python
Script\n')\n");
  // shut down the interpreter
  Py_Finalize();
  return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060116/c79540a9/attachment.html

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

2006年01月16日 星期一 16:25

Qiangning Hong hongqn at gmail.com
Mon Jan 16 16:25:34 HKT 2006

nicran wrote:
> 大家好,我在跑下面的例子的时候,得到如下错误,请各位给个线索,怎么解决。
> 多谢了
>  
>  
> /Temp/ccqv0PBa.o(.text+0x1f):my.c: undefined reference to `_Py_Initialize'
> /Temp/ccqv0PBa.o(.text+0x2b):my.c: undefined reference to
> `_PyRun_SimpleString'
> /Temp/ccqv0PBa.o(.text+0x37):my.c: undefined reference to
> `_PyRun_SimpleString'
> /Temp/ccqv0PBa.o(.text+0x3c):my.c: undefined reference to `_Py_Finalize'
> collect2: ld returned 1 exit status
>  
>  
> ---- my command ----
> gcc temp.c -I/usr/include/python2.4

没有链接python的库

-- 
Qiangning Hong
http://hongqn.hn.org
Registered Linux User #396996

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

2006年01月16日 星期一 16:27

RichardLee RichardLee at e28.com
Mon Jan 16 16:27:33 HKT 2006

It seems you need link python lib as gcc argument, like:

Gcc temp.c ¨CI/usr/include/python2.4 ¨CLmodule_path ¨Clmodule_name

The module_path and module_name you can refer as the python manual!

 

Best Regards

Richard Lee

  _____  

·¢¼þÈË: python-chinese-bounces at lists.python.cn
[mailto:python-chinese-bounces at lists.python.cn] ´ú±í nicran
·¢ËÍʱ¼ä: 2006Äê1ÔÂ16ÈÕ 16:22
ÊÕ¼þÈË: python-chinese at lists.python.cn
Ö÷Ìâ: Spam:[python-chinese] embed python interpreter in c -- help

 

´ó¼ÒºÃ£¬ÎÒÔÚÅÜÏÂÃæµÄÀý×ÓµÄʱºò£¬µÃµ½ÈçÏ´íÎó£¬Çë¸÷λ¸ø¸öÏßË÷£¬Ôõô½â¾ö¡£¶àл
ÁË

 

 

/Temp/ccqv0PBa.o(.text+0x1f):my.c: undefined reference to `_Py_Initialize'
/Temp/ccqv0PBa.o(.text+0x2b):my.c: undefined reference to
`_PyRun_SimpleString'
/Temp/ccqv0PBa.o(.text+0x37):my.c: undefined reference to
`_PyRun_SimpleString' 
/Temp/ccqv0PBa.o(.text+0x3c):my.c: undefined reference to `_Py_Finalize'
collect2: ld returned 1 exit status
 

 

---- my command ----

gcc temp.c -I/usr/include/python2.4

 

---- temp.c -----

#include 
#include 
int main(int argc, char * argv[])
{
  // initialize the interpreter
  Py_Initialize();
  // evaluate some code
  PyRun_SimpleString("import sys\n"); 
  //ignore line wrap on following line
  PyRun_SimpleString("sys.stdout.write('Hello from an embedded Python
Script\n')\n");
  // shut down the interpreter
  Py_Finalize();
  return 0;
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060116/09a37a55/attachment.htm

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

2006年01月16日 星期一 16:31

nicran nicran at gmail.com
Mon Jan 16 16:31:17 HKT 2006

请原谅我的问题过于naive,如何链接啊? :$


在06-1-16,Qiangning Hong <hongqn at gmail.com> 写道:
>
> nicran wrote:
> > 大家好,我在跑下面的例子的时候,得到如下错误,请各位给个线索,怎么解决。
> > 多谢了
> >
> >
> > /Temp/ccqv0PBa.o(.text+0x1f):my.c: undefined reference to
> `_Py_Initialize'
> > /Temp/ccqv0PBa.o(.text+0x2b):my.c: undefined reference to
> > `_PyRun_SimpleString'
> > /Temp/ccqv0PBa.o(.text+0x37):my.c: undefined reference to
> > `_PyRun_SimpleString'
> > /Temp/ccqv0PBa.o(.text+0x3c):my.c: undefined reference to `_Py_Finalize'
> > collect2: ld returned 1 exit status
> >
> >
> > ---- my command ----
> > gcc temp.c -I/usr/include/python2.4
>
> 没有链接python的库
>
> --
> Qiangning Hong
> http://hongqn.hn.org
> Registered Linux User #396996
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060116/997a5cbb/attachment.html

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

2006年01月16日 星期一 16:59

Qiangning Hong hongqn at gmail.com
Mon Jan 16 16:59:22 HKT 2006

nicran wrote:
> 请原谅我的问题过于naive,如何链接啊? :$

hongqn at r52 ~/tmp $ gcc test.c -I/usr/include/python2.4
-L/usr/lib/python2.4/config/ -lpython2.4 -lm -ldl -lpthread -lutil


-- 
Qiangning Hong
http://hongqn.hn.org
Registered Linux User #396996

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

2006年01月16日 星期一 17:28

nicran nicran at gmail.com
Mon Jan 16 17:28:48 HKT 2006

QN, thank you very much for your kindly help

在06-1-16,Qiangning Hong <hongqn at gmail.com> 写道:
>
> nicran wrote:
> > 请原谅我的问题过于naive,如何链接啊? :$
>
> hongqn at r52 ~/tmp $ gcc test.c -I/usr/include/python2.4
> -L/usr/lib/python2.4/config/ -lpython2.4 -lm -ldl -lpthread -lutil
>
>
> --
> Qiangning Hong
> http://hongqn.hn.org
> Registered Linux User #396996
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060116/c4dc08a1/attachment.htm

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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号