473,406 Members | 2,220 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,406 software developers and data experts.

Win32 Libs for 2.4

Does anyone know if it is feasible to have static libraries for both 2.3 and 2.4
compatible extensions. I'm worrying about libjpeg etc in a win32 environment.

--
Robin Becker
Jul 18 '05 #1
9 1415
Robin Becker wrote:
Does anyone know if it is feasible to have static libraries for both 2.3
and 2.4 compatible extensions. I'm worrying about libjpeg etc in a win32
environment.


Could you be a bit more specific:

do you want to create a binary python extension that is compatible with
both Python 2.3 and Python 2.4.

Or do you want to create a static lib containing both the original C lib
and the code for your extension? This Lib should then be linked with the
proper python2*.lib to create a version specific binary extension.

Or something else?

The first one is not possible as far as I know because python2*.lib
tries to load a specific python2*.dll. You could try to replace static
DLL import with dynamic DLL import (loading the DLL explizit and getting
the function pointers by name). That would be a lot of work and I don't
know how well it works for global variables (like all the type objects).
On the other hand, many people find it annoying that you have to build
new exte8ensions for every Python version, so this could be something a
lot of people have an interest in.

I solved this problem by putting .pyd for several versions into the
download. The right one is picked at runtime by checking sys.version.

Creating one lib which is then linked to python2*.lib works most of the
time, but you'll probably get a warning during loading of the module
that the extension has been compiled for a different version of the API.

Daniel
Jul 18 '05 #2
Daniel Dittmar wrote:
Robin Becker wrote:
Does anyone know if it is feasible to have static libraries for both
2.3 and 2.4 compatible extensions. I'm worrying about libjpeg etc in a
win32 environment.

Could you be a bit more specific:

do you want to create a binary python extension that is compatible with
both Python 2.3 and Python 2.4.


not this one
Or do you want to create a static lib containing both the original C lib
and the code for your extension? This Lib should then be linked with the
proper python2*.lib to create a version specific binary extension.

not this one either
Or something else?

actually I want to build the PIL extension for 2.4 as pyd and include various
libraries eg zlib and jpeg. To avoid the missing dlls issue we have done this in
the past by incorporating the zlib/jpeg code using static libraries for both
zlib and jpeg.

It seems I can use the static lib built with MSC 6 with the extension code
compiled with MSC 7.1. At least the extnsion build doesn't complain. Whether
this is really allowed is another matter.
..... Daniel

--
Robin Becker

Jul 18 '05 #3
Robin Becker wrote:
actually I want to build the PIL extension for 2.4 as pyd and include
various libraries eg zlib and jpeg. To avoid the missing dlls issue we
have done this in the past by incorporating the zlib/jpeg code using
static libraries for both zlib and jpeg.

It seems I can use the static lib built with MSC 6 with the extension
code compiled with MSC 7.1. At least the extnsion build doesn't
complain. Whether this is really allowed is another matter.


I guess that it won't work if something malloc'ed from the MSC 6 runtime
is free'd by the MSC 7.1 runtime.

zlib is also part of the Python sources on Windows, so it shouldn't be a
problem to build it for PIL.

I'm not sure what effort would be needed to build jpeg lib using MSC
7.1. My guess would be that there is hardly any effort if an nmake file
exists and a bit more work if you only have MS VC project file.

Daniel
Jul 18 '05 #4
Daniel Dittmar wrote:
Robin Becker wrote:
actually I want to build the PIL extension for 2.4 as pyd and include
various libraries eg zlib and jpeg. To avoid the missing dlls issue we
have done this in the past by incorporating the zlib/jpeg code using
static libraries for both zlib and jpeg.

It seems I can use the static lib built with MSC 6 with the extension
code compiled with MSC 7.1. At least the extnsion build doesn't
complain. Whether this is really allowed is another matter.

I guess that it won't work if something malloc'ed from the MSC 6 runtime
is free'd by the MSC 7.1 runtime.

.......

I thought that static .libs didn't make reference to the dll's they need; isn't
that done at load time?

As for rebuilding that's easy; the hard part is having all the versions
available at once. I prefer to keep common code in one place so would prefer to
have only one static lib for these non version dependant things.


Daniel

--
Robin Becker

Jul 18 '05 #5
Robin Becker wrote:
I guess that it won't work if something malloc'ed from the MSC 6
runtime is free'd by the MSC 7.1 runtime.


I thought that static .libs didn't make reference to the dll's they
need; isn't that done at load time?


You're right, DLL-phobia made my thinking less than precise.

The other things I could think of might not apply in this case:
- Routines accessing the elements of FILE* directly. I though library
designers had learned not to export this, but stdio.h still shows it and
some macros from that header file might use it (a problem only if the
definitions in MSC 6 and MSC 7.1 differ)
- calling conventions: in the past, that was a problem mostly with
functions returning structs. (Meaning caller and callee would implement
it differently if they were compiled by different compilers)

Daniel
Jul 18 '05 #6
Robin Becker wrote:
I thought that static .libs didn't make reference to the dll's they
need; isn't that done at load time?


Unfortunately, thanks to Microsoft's infinite wisdom, static libs
*do* reference DLLs. The C lib headers contain things like

#pragma lib("msvcrt.lib") // or some such

The compiler translates this into a reference to the DLL in the
object file, which the linker will then translate into a reference
to the DLL when linking, even if the DLL was not giving on the linker
command line.

However, I am uncertain how this works with multiple VC versions -
whether the DLL reference is CRT version independent or not.
You should view the resulting extension module in depends.exe,
and check whether it refers to multiplce CRT dlls (which would be
bad).

Regards,
Martin
Jul 18 '05 #7
Martin v. Löwis wrote:
Robin Becker wrote:
I thought that static .libs didn't make reference to the dll's they
need; isn't that done at load time?

Unfortunately, thanks to Microsoft's infinite wisdom, static libs
*do* reference DLLs. The C lib headers contain things like

#pragma lib("msvcrt.lib") // or some such


according to my docs

there's something called a comment pragma used thusly

#pragma comment( lib, "xxx.lib" )

which places a search record into the obj file. I don't think this forces the
linker to load stuff from this module although I can see that it might be
dangerous depending on which obj files are seen first.

The compiler translates this into a reference to the DLL in the
object file, which the linker will then translate into a reference
to the DLL when linking, even if the DLL was not giving on the linker
command line.
I believe this is a weak reference from the documentation.

However, I am uncertain how this works with multiple VC versions -
whether the DLL reference is CRT version independent or not.
You should view the resulting extension module in depends.exe,
and check whether it refers to multiplce CRT dlls (which would be
bad).

well in my 2.4 _imaging.pyd I see direct references to only msvcr71.dll,
but there is a direct reference to USER32.dll which references ADVAPI32.dll
which references WINTRUST.dll which then references msvcrt.dll. Fortunately I
don't think this is a problem as Python24.dll also references USER32.dll directly.

Perhaps a genius level cretifiable (whoops Freudian mispelling of certified)
knows whether this is OK.

Regards,
Martin

--
Robin Becker

Jul 18 '05 #8
Robin Becker wrote:
I don't think this
forces the linker to load stuff from this module although I can see that
it might be dangerous depending on which obj files are seen first.
I think you are wrong. In the object, there will be simply a linker
command line option encoded; do "dumpbin /all foo.obj" to see the
linker options.
I believe this is a weak reference from the documentation.
What makes you think so?: the linker option in the object file will
be added to the linker line, unconditionally.
Fortunately I don't think this is a problem as Python24.dll also
references USER32.dll directly.


Yes, that user32.dll indirectly uses msvcrt.dll should be no problem.

Regards,
Martin
Jul 18 '05 #9
Martin v. Löwis wrote:
Robin Becker wrote:
I don't think this forces the linker to load stuff from this module
although I can see that it might be dangerous depending on which obj
files are seen first.

I think you are wrong. In the object, there will be simply a linker
command line option encoded; do "dumpbin /all foo.obj" to see the
linker options.


yes I understood that, but I thought

Linker Directives
-----------------
-defaultlib:MSVCRT
-defaultlib:OLDNAMES

doesn't force the code to use entrypoints in those libs so I consider it
weak. Anyhow despite these records being in the static library object
files it doesn't seem to have forced msvcrt to be used directly. I
assume that this is because earlier objects have brought in a library
which already satisfies the externals. Or perhaps I'm just lucky in that
the libjpeg routines don't actually use anything from msvcrt.

....... Yes, that user32.dll indirectly uses msvcrt.dll should be no problem.
Regards,
Martin

--
Robin Becker
Jul 18 '05 #10

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

Similar topics

4
by: John Hunter | last post by:
I am using distutils to build a python extension module on win32. I initialize the Extension class with a list of libraries with Extension("_gd", , include_dirs=incdirs, library_dirs=libdirs,...
9
by: Tzu-Chien Chiu | last post by:
Hi, "What methods do you ever use to optimize the programs?" We're developing a graphics chip emulator in C++, but it's very slow for big scenes. Even though this is a cross-platform software,...
98
by: jacob navia | last post by:
<< QUOTE It is NOT a C compiler, because it doesn't conform to any commonly accepted C specification (K&R, C89, C99). You have no right to call it a C compiler until you get it to conform quote...
15
by: Bryan | last post by:
I have a multi-threaded C# console application that uses WMI (System.Management namespace) to make RPC calls to several servers (600+ ) and returns ScheduledJobs. The section of my code that...
3
by: Sygnosys | last post by:
Hi, I have a piece of code in .NET that encrypts a string. The .NET code is quite simple and through the last couple of days I've been trying to build it's equivalent in ATL playing arround...
9
by: eeh | last post by:
Hi, I am extremely new to write C programs by GCC. I need to port a C program from GCC(Linux) to GCC(Win32). However, the following errors during compilation: powerSwitch.c `random'...
2
by: dragonslayer008 | last post by:
I moved some unmanaged C++ code into a C++/CLI project. The unmanaged code makes some Win32 API calls. I thought as long as I kept the API calls in a native class, it would integrate seamlessly. ...
0
by: newbie73 | last post by:
Going through the tutorial on http://swig.org, I created the example files (pasted below). After generating the _wrap file, I tried compiling (using mingw32) and received a lot of undefined...
0
by: mani | last post by:
Hi I'm bringing up an old story once more! I'm on win32 (winxp sp2) python 2.4.4. mingw gcc version is 3.4.5. msys is in c:\msys. mingw is in c:\mingw and python is in c:\pyton24. there is also...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
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,...
0
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...

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.