473,509 Members | 2,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem: embedding Python

mmf
Hallo!

I tried to use Python from C like it is described in the Python
Docmentation. So I wrote the following C source file:

#include <Python.h>
int
main(int argc, char *argv[])
{
Py_Initialize();
PyRun_SimpleString("print 'Hallo World!'\n");
Py_Finalize();
return 0;
}

I saved it as run.c and tried to compile it using the following
command:
gcc run.c

But that always results in a list of errors:

/tmp/cc1tmrPU.o(.text+0x1d): In function `main':
: undefined reference to `Py_Initialize'
/tmp/cc1tmrPU.o(.text+0x2a): In function `main':
: undefined reference to `PyRun_SimpleString'
/tmp/cc1tmrPU.o(.text+0x32): In function `main':
: undefined reference to `Py_Finalize'

What am I doing wrong? Can you help me?

Tanks.

Best regards,
Markus

Jul 19 '05 #1
1 1424
mmf wrote:
Hallo!

I tried to use Python from C like it is described in the Python
Docmentation. So I wrote the following C source file:

#include <Python.h>
int
main(int argc, char *argv[])
{
Py_Initialize();
PyRun_SimpleString("print 'Hallo World!'\n");
Py_Finalize();
return 0;
}

I saved it as run.c and tried to compile it using the following
command:
gcc run.c

But that always results in a list of errors:

/tmp/cc1tmrPU.o(.text+0x1d): In function `main':
: undefined reference to `Py_Initialize'
/tmp/cc1tmrPU.o(.text+0x2a): In function `main':
: undefined reference to `PyRun_SimpleString'
/tmp/cc1tmrPU.o(.text+0x32): In function `main':
: undefined reference to `Py_Finalize'

What am I doing wrong? Can you help me?

Tanks.

Best regards,
Markus


You should link with Python's shared object (replace with your version
of Python):
gcc -o run run.c -I/usr/include/python2.4 -lpython2.4

--
Are you a riddle lover?
Try http://www.pythonchallenge.com
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1830
by: Atul Kshirsagar | last post by:
I am embedding python in my C++ application. I am using Python *2.3.2* with a C++ extention DLL in multi-threaded environment. I am using SWIG-1.3.19 to generate C++ to Python interface. Now to...
4
2760
by: Alicia Haumann | last post by:
I accidentally sent this to webmaster@python.org, so this could be a duplicate if "webmaster" forwards it to this list. :{ Hi, there. Thanks for any help that can be offered. I've been...
6
4208
by: John Dean | last post by:
Hi I spent the whole of yesterday trying the get the following C code to execute PyRun_String("def title();", Py_file_input, dict, dict); PyRun_String("\treturn 'Foo Bar'", Py_file_input,...
1
2557
by: Benke | last post by:
Hello, I'm quite new to Python and embedding python in c++. I'm trying to write a function that i can use to call a python function. It should take 3 arguments, the name of the python file, the...
0
1337
by: DevEng | last post by:
Hi all, I am new to Python and trying to embed it into a c/c++ application. I started with examples from the documentation pages and go to the Pure Embedding example...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7416
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7073
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.