Erros when compiling a CPP program which uses CPython API functions

G

grbgooglefan

I am compiling CPP program which uses CPython API functions from
Python 2.5.1 source code

First I compiled with this commanline, that time I got "pyconfig.h"
not found.
g++ -Os -I../../Include ../../libpython2.5.a -lm -ldl -lpthread -lutil
testeval.cpp
In file included from testeval.cpp:1:
.../../Include/Python.h:8:22: pyconfig.h: No such file or directory
In file included from ../../Include/Python.h:57, from
testeval.cpp:1:
.../../Include/pyport.h:4:48: pyconfig.h: No such file or directory
.../../Include/pyport.h:734:2: #error "LONG_BIT definition appears
wrong for platform (bad gcc/glibc config?)."

So, I added "-I../../PC" to my cmd line to get pyconfig.h, like:
g++ -Os -I../../Include -I../../PC/ ../../libpython2.5.a -lm -ldl -
lpthread -lutil testeval.cpp

As soon as I ran this command I got a long list of errors as shown
below.
Why the dllimport errors are coming? I did not get these errors when I
did same compilation with Python 2.2.3.
Please help. Thanks.

In file included from ../../Include/Python.h:76, from
testeval.cpp:1:
.../../Include/pymem.h:50: `dllimport' was not declared in this scope
.../../Include/pymem.h:50: ISO C++ forbids declaration of `__declspec'
with no type
.../../Include/pymem.h:50: syntax error before `void'
.../../Include/pymem.h:51: `dllimport' was not declared in this scope
.../../Include/pymem.h:51: ISO C++ forbids declaration of `__declspec'
with no type
.../../Include/pymem.h:51: redefinition of `int __declspec'
.../../Include/pymem.h:50: `int __declspec' previously defined here
.../../Include/pymem.h:51: syntax error before `void'
.../../Include/pymem.h:52: `dllimport' was not declared in this scope
.../../Include/pymem.h:52: ISO C++ forbids declaration of `__declspec'
with no type
.../../Include/pymem.h:52: redefinition of `int __declspec'
.../../Include/pymem.h:51: `int __declspec' previously defined here
.../../Include/pymem.h:52: syntax error before `void'
In file included from ../../Include/Python.h:78, from
testeval.cpp:1:
.../../Include/object.h:371: `dllimport' was not declared in this scope
.../../Include/object.h:371: ISO C++ forbids declaration of
`__declspec' with no type
.../../Include/object.h:371: redefinition of `int __declspec'
...............
.../../Include/Python.h:134: redefinition of `int __declspec'
.../../Include/pystrtod.h:11: `int __declspec' previously defined here
.../../Include/Python.h:134: syntax error before `*' token
testeval.cpp: In function `int main(int, char**)':
testeval.cpp:94: `Py_Initialize' undeclared (first use this function)
testeval.cpp:94: (Each undeclared identifier is reported only once for
each
function it appears in.)
testeval.cpp:95: `PyRun_SimpleStringFlags' undeclared (first use this
function)
 
G

grbgooglefan

I am compiling CPP program which uses CPython API functions from
Python 2.5.1 source code

First I compiled with this commanline, that time I got "pyconfig.h"
not found.
g++ -Os -I../../Include ../../libpython2.5.a -lm -ldl -lpthread -lutil
testeval.cpp
In file included from testeval.cpp:1:
../../Include/Python.h:8:22: pyconfig.h: No such file or directory
In file included from ../../Include/Python.h:57, from
testeval.cpp:1:
../../Include/pyport.h:4:48: pyconfig.h: No such file or directory
../../Include/pyport.h:734:2: #error "LONG_BIT definition appears
wrong for platform (bad gcc/glibc config?)."

So, I added "-I../../PC" to my cmd line to get pyconfig.h, like:
g++ -Os -I../../Include -I../../PC/ ../../libpython2.5.a -lm -ldl -
lpthread -lutil testeval.cpp

As soon as I ran this command I got a long list of errors as shown
below.
Why the dllimport errors are coming? I did not get these errors when I
did same compilation with Python 2.2.3.
Please help. Thanks.

In file included from ../../Include/Python.h:76, from
testeval.cpp:1:
../../Include/pymem.h:50: `dllimport' was not declared in this scope
../../Include/pymem.h:50: ISO C++ forbids declaration of `__declspec'
with no type
../../Include/pymem.h:50: syntax error before `void'
../../Include/pymem.h:51: `dllimport' was not declared in this scope
../../Include/pymem.h:51: ISO C++ forbids declaration of `__declspec'
with no type
../../Include/pymem.h:51: redefinition of `int __declspec'
../../Include/pymem.h:50: `int __declspec' previously defined here
../../Include/pymem.h:51: syntax error before `void'
../../Include/pymem.h:52: `dllimport' was not declared in this scope
../../Include/pymem.h:52: ISO C++ forbids declaration of `__declspec'
with no type
../../Include/pymem.h:52: redefinition of `int __declspec'
../../Include/pymem.h:51: `int __declspec' previously defined here
../../Include/pymem.h:52: syntax error before `void'
In file included from ../../Include/Python.h:78, from
testeval.cpp:1:
../../Include/object.h:371: `dllimport' was not declared in this scope
../../Include/object.h:371: ISO C++ forbids declaration of
`__declspec' with no type
../../Include/object.h:371: redefinition of `int __declspec'
..............
../../Include/Python.h:134: redefinition of `int __declspec'
../../Include/pystrtod.h:11: `int __declspec' previously defined here
../../Include/Python.h:134: syntax error before `*' token
testeval.cpp: In function `int main(int, char**)':
testeval.cpp:94: `Py_Initialize' undeclared (first use this function)
testeval.cpp:94: (Each undeclared identifier is reported only once for
each
function it appears in.)
testeval.cpp:95: `PyRun_SimpleStringFlags' undeclared (first use this
function)

I am doing this on following Linux OS config:
Linux njl36a-7003 2.4.21-9.0.1.ELsmp #1 SMP Mon Feb 9 22:26:51 EST
2004 i686 i686 i386 GNU/Linux
cat /etc/redhat-release
Red Hat Enterprise Linux AS release 3 (Taroon Update 1)
 
G

grbgooglefan

I am doing this on following Linux OS config:
Linux njl36a-7003 2.4.21-9.0.1.ELsmp #1 SMP Mon Feb 9 22:26:51 EST
2004 i686 i686 i386 GNU/Linux>cat /etc/redhat-release

Red Hat Enterprise Linux AS release 3 (Taroon Update 1)- Hide quoted text -

- Show quoted text -

This is resolved when I used the pyconfig.h file not from Python-2.5.1/
PC/pyconfig.h but the top level which is Python-2.5.1/pyconfig.h
 
C

Christian Heimes

grbgooglefan said:
I am compiling CPP program which uses CPython API functions from
Python 2.5.1 source code

First I compiled with this commanline, that time I got "pyconfig.h"
not found.

On Unix you have to run ./configure and make before you can use a source
tree. It creates a valid pyconfig.h for you. You may want to use the
../configure option --enable-shared.
So, I added "-I../../PC" to my cmd line to get pyconfig.h, like:

PC/pyconfig.h is for Windows only!


Christian
 
G

grbgooglefan

On Unix you have to run ./configure and make before you can use a source
tree. It creates a valid pyconfig.h for you. You may want to use the
./configure option --enable-shared.


PC/pyconfig.h is for Windows only!

Christian

Thanks for this guidance.
I just now compiled Python 2.5.1 in my home directory. The Linux
machine has Python 2.2.3 already installed.
When I run my above mentioned program which is linked with
libpython2.5.1.a, I get an error as below:

gborse@njl36a-7003:~/prgs/bakup/Python-2.5.1/Demo/embed>./a.out ~/pxm/
parserroot/
'import site' failed; use -v for traceback
['/home/gborse/prgs/bakup/Python-2.5.1/lib/python25.zip', '/home/
gborse/prgs/bakup/Python-2.5.1/lib/python2.5/', '/home/gborse/prgs/
bakup/Python-2.5.1/lib/python2.5/plat-linux2', '/home/gborse/prgs/
bakup/Python-2.5.1/lib/python2.5/lib-tk', '/home/gborse/prgs/bakup/
Python-2.5.1/lib/python2.5/lib-dynload']

I have set the PYTHONHOME to /home/gborse/prgs/bakup/Python-2.5.1 and
PYTHON_LIB to /home/gborse/prgs/bakup/Python-2.5.1/Lib/

But if I run this simialr program compiled with Python2.2.3, it does
not give this error of "import site" failed.
I don't understand how come the "python2.5" is getting appended to
PYTHON_LIB when this "import site" error is coming?

How do we resolve this error?
 
C

Christian Heimes

grbgooglefan said:
> How do we resolve this error?

The easiest way to solve all your problems is: make altinstall.

It installs Python in PREFIX (usually /usr/local). Although it is
possible to run Python in a build directory it is tricky and may not
work for your own program.

Christian
 
C

Christian Heimes

grbgooglefan said:
> How do we resolve this error?

The easiest way to solve all your problems is: make altinstall.

It installs Python in PREFIX (usually /usr/local). Although it is
possible to run Python in a build directory it is tricky and may not
work for your own program.

Christian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top