473,381 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,381 software developers and data experts.

Erros when compiling a CPP program which uses CPython API functions

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
6 2809
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Reinhard Abel | last post by:
I have an old C-Program written with Borland 2.0. Now I like to do some changes, but I get lot of syntax Erros with my new computer. When I use the old mashine ( 286 ) it works perfectly but I can...
3
by: Baloff | last post by:
how do find out what the command line flag that forces a C compilation for my gcc 3.3.5-3, I am doing an exercise and am asked to note the difference between C and C++ compilation of a code which...
0
by: Scott Chang | last post by:
Hi all, I tried to use Managed C++ coding of VC++.NET (2002)and OpenGL version 1.2 to draw a hexagon shape of benzene. My OpenGLdrawBenzene.cpp is the following: // This is the main project file...
19
by: Simon Faulkner | last post by:
Pardon me if this has been done to death but I can't find a simple explanation. I love Python for it's ease and speed of development especially for the "Programming Challenged" like me but why...
0
by: capes | last post by:
have functions in my cell model calling CVODE for each time step. When I build the application I get a number of link errors: \cardiacsimulator.o Release\ccardiaccell.o Release\ccelldata.o...
9
by: Sheldon | last post by:
Good day Everyone, I am a still very new at learning C and I have thrown myself in the deep end. I started with a simple program and kept widening the scope. This has taught me many things about...
1
by: Christof Hoeke | last post by:
hi, I was wondering if there is any way to use XSLT2 or maybe even XQuery with "normal" CPython. Using Saxon/XSLT2 with Jython is no problem (I have not tried Saxon.NET with IronPython but suspect...
8
by: Horacius ReX | last post by:
Hi, I am developing some code in C which first I compile on my linux machine and afterwards I test on another special hardware which has almost no debug capabilities at all. Usually I get a lot...
11
by: r0g | last post by:
I'm collecting together a bunch of fairly random useful functions I have written over the years into a module. Generally speaking is it best to a) Import all the other modules these functions...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.