473,498 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SIP Python/C++ binding fails to compile

5 New Member
Hi all!

After successfully compiling a Python/C binding with SIP I wanted to do the same thing with Python/C++. For some reason this doesn't work.

Here's the files:

fib.cpp
-----------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. #include "fib.h"
  2.  
  3. int fib1(int n)
  4. {
  5.     if (n <= 0) {
  6.         return 0;
  7.     } else if (n <= 2) {
  8.         return 1;
  9.     } else {
  10.         return fib1(n-1) + fib1(n-2);
  11.     }
  12. }
  13.  
fib.h
-----------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. int fib1(int n);
  2.  
fib.sip
-----------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. %Module fib
  2.  
  3. %Include fib.h
  4.  
I run the following command to build the intermediate files:
sip -c . fib.sip

So far everything works.

Now I want to build the .pyd file using distutils.

setup.py
-----------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. from distutils.core import setup, Extension
  2. import sipdistutils
  3.  
  4. setup(
  5.   name = 'fib',
  6.   versione = '1.0',
  7.   ext_modules=[
  8.     Extension("fib", ["fib.sip", "fib.cpp"]),
  9.     ],
  10.  
  11.   cmdclass = {'build_ext': sipdistutils.build_ext}
  12. )
  13.  
I run the following command:
python setup.py build

This fails with the following error:
build\temp.win32-2.7\Release\sipfibcmodule.cpp:29:29: error: 'fib1' was not declared in this scope
error: command 'gcc' failed with exit status 1

What could the problem be? Shouldn't c++ be used as a compiler instead of gcc, by the way?

Any help appreciated!

Kind regards

David
May 25 '12 #1
1 2400
davidraimosson
5 New Member
I've found a solution that is good enough: namespaces. Next time I'll read the documentation better. I should also mention that a solution with a Fibonacci class could solve the problem, but I didn't find that to be satisfying.

Below the content of the files can be found.

fib.cpp

Expand|Select|Wrap|Line Numbers
  1. #include "fib.h" 
  2.  
  3. namespace test 
  4.     int fib1(int n) 
  5.     { 
  6.         if (n <= 0) { 
  7.             return 0; 
  8.         } else if (n <= 2) { 
  9.             return 1; 
  10.         } else { 
  11.             return fib1(n-1) + fib1(n-2); 
  12.         } 
  13.     } 
  14. }
  15.  
fib.h

Expand|Select|Wrap|Line Numbers
  1. namespace test 
  2.     int fib1(int n); 
  3. }
  4.  
fib.sip

Expand|Select|Wrap|Line Numbers
  1. %Module fib 
  2.  
  3. namespace test { 
  4.     %TypeHeaderCode 
  5.     #include "fib.h" 
  6.     %End 
  7.  
  8.     int fib1(int n); 
  9. }; 
  10.  
setup.py was left untouched.

Exactly the same commands as mentioned before were used.
May 26 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1502
by: Terry Reedy | last post by:
>From http://film.nvidia.com/page/gelato.html : Gelato is NVIDIA's new professional image rendering software, running on top of its new Quadro FX graphics hardware. In addition to its C++ API, ...
0
1193
by: Tim Churches | last post by:
These days, what is the best way to transform DocBook XML into HTML, RTF, PDF and other targets using Python? Googling around the topic throws up a bewildering array of acronyms, but it seem that...
17
3095
by: newbiecpp | last post by:
I have hard time to understand run-time environment. Let assume that I have a program that has a simple variable alpha. When this variable is statically allocated, the compiler can use the...
1
2135
by: bmcnally | last post by:
I can't tell from the documentation, but I'd like to try and print unicode characters through Python's binding to ncurses. From reading the documentation on the curses module, it doesn't appear...
2
3677
by: kogrover | last post by:
ISSUE: COM Excel Sort works with Early Binding, but not Late Binding, but py2exe only does Late Binding I have code similar to this (type from notes, so there may be a typo...) import...
10
3218
by: Alex Li | last post by:
Hello, I would like to use Python 2.5 on Windows with Graphviz to generate graphs. I used yapgvb but it only requires Python 2.4 (won't work with Python 2.5). Other packages like pydot seems...
7
1855
by: Georg Grabler | last post by:
Hello everybody. There's a C library which i'd like to have python bindings for. I havn't known anything before about how to write python bindings for a C library. I succeeded now by using...
1
5022
by: Daniel Nogradi | last post by:
It might be slightly off topic here but couldn't find a more suitable place for this question: I'm trying to build the python binding for ming -- http://ming.sf.net -- but for some reason the...
0
994
by: shekaranjanappa | last post by:
Hi I have a requirement to do follwing operation in looop 1. open socket 2. start 3. bind 4. listion 5. close socket Here used ip address and port is same always.
8
3253
by: Fett | last post by:
I am trying to find a wrapper to do linear programming within python. I am using an ubuntu machine and I have apt-get'd lp_solve, which works just fine. If someone knows of a wrapper that will work...
0
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7165
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
7203
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...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5462
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,...
1
4908
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4588
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
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
1417
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 ...

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.