By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,723 Members | 1,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,723 IT Pros & Developers. It's quick & easy.

Erros when compiling a CPP program which uses CPython API functions

P: n/a
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)
Dec 7 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Dec 7, 12:32 pm, grbgooglefan <ganeshbo...@gmail.comwrote:
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)
Dec 7 '07 #2

P: n/a
On Dec 7, 2:17 pm, grbgooglefan <ganeshbo...@gmail.comwrote:
On Dec 7, 12:32 pm, grbgooglefan <ganeshbo...@gmail.comwrote:


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)- 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
Dec 7 '07 #3

P: n/a
grbgooglefan wrote:
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

Dec 7 '07 #4

P: n/a
On Dec 7, 5:15 pm, Christian Heimes <li...@cheimes.dewrote:
grbgooglefan wrote:
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
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/Pyth.../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?
Dec 7 '07 #5

P: n/a
grbgooglefan wrote:
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

Dec 7 '07 #6

P: n/a
grbgooglefan wrote:
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

Dec 7 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.