I'm trying to embed python script in c in windows.

#include <Python.h>

main(int argc, char *argv[])
  PyRun_SimpleString("from time import time,ctime\n"
                     "print 'Today is',ctime(time())\n");
  return 0;

from the python documentation.
I'm compiling with Microsoft's lcc.
I'm getting following errors.

Error c:\lcc\examples\python\pyembed.c 7 undefined reference to __imp__Py_Initialize
Error c:\lcc\examples\python\pyembed.c 8 undefined reference to __imp__PyRun_SimpleStringFlags
Error c:\lcc\examples\python\pyembed.c 10 undefined reference to __imp__Py_Finalize

I added python include files in the project.But I'm not sure what to do with py27.lib or py27.dll.That may be the problem I guess.

Recommended Answers

All 2 Replies

I don't know Microsoft's lcc, but you should probably link against the python library
(something like -lpy27 or -lpython ...). Also did you run the code in the linking requirements section

>>> import distutils.sysconfig
>>> distutils.sysconfig.get_config_var('LINKFORSHARED')

to get flags for the linker ?

yep I did

>>> import distutils.sysconfig
>>> distutils.sysconfig.get_config_var('LINKFORSHARED')

and it gave nothing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.