473,544 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem building extension under Cygwin (ImportError: Bad address)

Hi,

I have problems building a simple handcoded C-extension (hello.c) with
Cygwin and gcc3.4.4. I hope somebody has encountered the same problem
before, and has some advice.

The extension works just fine with Linux:

gcc -c hello.c -I/usr/local/include/python2.4/
ld -shared hello.o -o hello.so -L /usr/local/lib/ -lpython2.4 -lc
python -c'import hello;q = hello.message(" Lars");print q'
Hello, Lars

But doing a similar compile under Cygwin doesn't work so well:
(same options, but the output is called hello.dll and the directories
are a bit different)

$ python -c"import hello"
Traceback (most recent call last):
File "<string>", line 1, in ?
ImportError: Bad address

btw:
hello.c is from "Programmin g Python 2nd ed." by Mark Lutz. It's
published by O'Reilly. The code can be downloaded from:
http://examples.oreilly.com/python2/Examples.zip .
hello.c is in the directory PP2E\Integrate\ Extend\Hello.
-Lars

May 4 '06 #1
4 2044
Lars,

On Thu, May 04, 2006 at 03:50:13AM -0700, Lars wrote:
I have problems building a simple handcoded C-extension (hello.c) with
Cygwin and gcc3.4.4. I hope somebody has encountered the same problem
before, and has some advice.

[snip]


The following works for me:

$ gcc -shared -I/usr/include/python2.4 -o hello.dll hello.c -L/usr/lib/python2.4/config -lpython2.4
$ python -c'import hello;q = hello.message(" Lars");print q'
Hello, Lars
$ python hellouse.py
Hello, C
Hello, module /tmp/Examples/PP2E/Integrate/Extend/Hello/hello.dll
Hello, 0
Hello, 1
Hello, 2

Note I had to apply the attached patch to get hello.c to compile.

Jason

--
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6

May 4 '06 #2
Thanks Jason, it works now.

There seems to be some sort of issue with ld in cygwin when compiling
shared libraries (e.g. DLL's).
This worked on my Cygwin installation also:

------------------------------
gcc hello.c -I/usr/include/python2.4/ -L/usr/lib/python2.4/config/
-lpython2.4 -shared -o hello.dll
python hellouse.py
(gives the right answer)
--------------------------------

But first compiling hello.c with gcc, then linking it with gnu-ld just
won't work. I only really need to compile one C-file to a shared
library so it doesn't matter so much for me. But bigger projects will
have a problem..

------------------------------------------
gcc -c hello.c -I/usr/include/python2.4/
ld -shared hello.o -o hello.so -L /usr/lib/python2.4/config -lpython2.4
-lc
python hellouse.py
Traceback (most recent call last):
File "hellouse.p y", line 1, in ?
import hello
ImportError: Bad address
-------------------------------------------

-Lars

May 4 '06 #3
On Thu, May 04, 2006 at 06:23:23AM -0700, Lars wrote:
But first compiling hello.c with gcc, then linking it with gnu-ld just
won't work. I only really need to compile one C-file to a shared
library so it doesn't matter so much for me. But bigger projects will
have a problem..


No, it works if you drive it from gcc:

$ gcc -I/usr/include/python2.4 -c hello.c
$ gcc -shared -o hello.dll hello.o -L/usr/lib/python2.4/config -lpython2.4
$ python hellouse.py
Hello, C
Hello, module /tmp/examples/PP2E/Integrate/Extend/Hello/hello.dll
Hello, 0
Hello, 1
Hello, 2

BTW, if you use Distutils, then it will just work...

Jason

--
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6
May 4 '06 #4
Great!
Thanks for the advice.

Lars

May 4 '06 #5

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

Similar topics

0
2080
by: Phil Schmidt | last post by:
I'm attempting to follow the instructions at http://sebsauvage.net/python/mingw.html, without luck. I have Python 2.3, MinGW 3.2.3, ans SWIG 1.3.19. I get an export error on "initexample" when attempting the example. Do I need some extra switches to get SWIG to create that function? Or is it something else? Here's my example build:
0
1750
by: Jose Vicente Nunez Z | last post by:
Greetings, I wrote a couple of custom dummy extensions in Python (one a pure Python and the other a C) and i managed to compile and install them without a problem: $ make python2 setup.py build running build
7
7159
by: Carl Waldbieser | last post by:
I tried to adapt the instructions for building the M2Crypto module (http://sandbox.rulemaker.net/ngps/m2/INSTALL.html) to build a version compatible with Python2.3, but I've had some mixed results. I actually got everything to build and install, but when I try to import M2Crypto-- well, here is a sample session: >>> import M2Crypto...
3
3886
by: Steve Holden | last post by:
If nobody has a quick answer I'll go to the PIL list, but I'm having problems with PIL JPEG support on Windows, and figured someone on c.l.py might have solved this problem. I built the Cygwin PIL from source, and that works a treat. Unfortunately the Windows version (1.1.4 and 1.1.5b1) loaded using binary installers is giving File...
2
1917
by: maxwell | last post by:
I'm trying to use the 'numarray' package (v1.1.1) under Python 2.4 running under CygWin. I initially downloaded the Windows executable version of the numarray package, and installed it under C:\program files\python\lib\site-packages. That works with the Windows version of Python, but not the CygWin version, where it fails with the msg:...
0
1330
by: Andreas | last post by:
Extension: --------------- pyshapelib 0.3 with Python 2.4 Problem: ------------- D:\Python24\Lib\site-packages\shapelib\setup>pytest.py Traceback (most recent call last): File "D:\Python24\Lib\site-packages\shapelib\setup\pytest.py", line 1, in ?
0
2340
by: Stewart Midwinter | last post by:
I have a Tkinter app running on cygwin. It includes a Test menu item that does nothing more than fetch a directory listing and display it in a Toplevel window (I'd use a tkMessageBox showinfo widget, but for some reason the text is invisible on cygwin). After I close the Toplevel widget, all of the menus in my app behave as though they...
1
1484
by: lennyw | last post by:
Hi I'm trying to build XMLgawk (latest version 3.1.5 from sourceforge) and I'm getting some make errors. I'm using the tool availbale from Cygwin to do the build (gcc, bash, make). I was able to run ./configure and I assume it ran without errors (at least there were no error messages on the console at the end of the run). But I get...
0
1383
by: Darrin Thompson | last post by:
I've been trying to build pyOpenSSL on Windows with Visual Studio 2003. I've hit the message below: building 'OpenSSL.SSL' extension creating build\temp.win32-2.5\Release\src\ssl C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -Ic:\OpenSSL\include -Ic:\Python25\include -Ic:\Python25\PC...
0
7374
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7632
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7783
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7720
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5931
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4930
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3430
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3422
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1850
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 we have to send another system

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.