Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to make py2.5 distutil to use VC2005?

3 views
Skip to first unread message

甜瓜

unread,
Jun 3, 2008, 10:38:30 PM6/3/08
to pytho...@python.org
Howdy,
This problem have puzzled me for a long time. I usually use
python2.5 in Windows, while VC2005 is installed.
However python25.lib is compiled by VC2003. When I use disutil to
build some C extensions, it complaints that
there is no VC2003.
Well, IMO, the format of binary files generated by VC2003 and
VC2005 is compatible in most cases. What
should I do to workaround this error? I mean, disable distutil
complaints and use VC2005 to build C extensions.
I have google-ed some discussion related on this topic. It seems that
it's real possible!
Thank you in advance.
--
ShenLei

Christian Heimes

unread,
Jun 4, 2008, 7:45:14 AM6/4/08
to pytho...@python.org
甜瓜 schrieb:

It's possible but ill-advised. The free mingw32 compiler can build
Python extensions just fine. I'm using it all the time to build Python
2.5 extensions for Windows.

In the future Python 2.6 and 3.0 are build with my VS 2008 system and
extensions can be build with the free express version, too.

Christian

David Cournapeau

unread,
Jun 4, 2008, 9:47:45 AM6/4/08
to 甜瓜, pytho...@python.org
On Wed, Jun 4, 2008 at 11:38 AM, 甜瓜 <littlesw...@gmail.com> wrote:

> Well, IMO, the format of binary files generated by VC2003 and
> VC2005 is compatible in most cases.

Problem arise with the C runtime, not with object file format. In
particular, python uses the C api for file handling, and the standard
C is definitely not ABI compatible within VS versions.

I strongly advise you against using VS 2005 (with the binary python;
if you build python by yourself, then no problem; I don't know if it
is possible to build python with VS 2005). You *will* get crashes in
many cases.

David

甜瓜

unread,
Jun 4, 2008, 9:40:29 PM6/4/08
to Christian Heimes, pytho...@python.org
2008/6/4 Christian Heimes <li...@cheimes.de>:

> 甜瓜 schrieb:
>> Howdy,
>> This problem have puzzled me for a long time. I usually use
>> python2.5 in Windows, while VC2005 is installed.
>> However python25.lib is compiled by VC2003. When I use disutil to
>> build some C extensions, it complaints that
>> there is no VC2003.
>> Well, IMO, the format of binary files generated by VC2003 and
>> VC2005 is compatible in most cases. What
>> should I do to workaround this error? I mean, disable distutil
>> complaints and use VC2005 to build C extensions.
>> I have google-ed some discussion related on this topic. It seems that
>> it's real possible!
>> Thank you in advance.
>
> It's possible but ill-advised. The free mingw32 compiler can build
> Python extensions just fine. I'm using it all the time to build Python
> 2.5 extensions for Windows.

Yep. Actually, I am using Cython for optimization on some parts of my code.
It indeed needs a good compiler to build binary from Cython scripts. Currently,
I employ MinGW for this task. Therefore I think, if VC2003-compiled python
runtime library can cooperate with MinGW, why not VC2003<->VC2005?
hehe.

>
> In the future Python 2.6 and 3.0 are build with my VS 2008 system and
> extensions can be build with the free express version, too.
>
> Christian
>

> --
> http://mail.python.org/mailman/listinfo/python-list

甜瓜

unread,
Jun 4, 2008, 9:57:59 PM6/4/08
to David Cournapeau, pytho...@python.org
2008/6/4 David Cournapeau <cour...@gmail.com>:

> On Wed, Jun 4, 2008 at 11:38 AM, 甜瓜 <littlesw...@gmail.com> wrote:
>
>> Well, IMO, the format of binary files generated by VC2003 and
>> VC2005 is compatible in most cases.
>
> Problem arise with the C runtime, not with object file format. In
> particular, python uses the C api for file handling, and the standard
> C is definitely not ABI compatible within VS versions.
Maybe VS runtime library is a problem, but I don't think VS binary is
in compatible with ISO C ABI. If so, VS-built application can not call
any function in libraries built by other C compiler even with __cdecl
extern "C" specifications.

> I strongly advise you against using VS 2005 (with the binary python;
> if you build python by yourself, then no problem; I don't know if it
> is possible to build python with VS 2005). You *will* get crashes in
> many cases.
>
> David
>

---
ShenLei

甜瓜

unread,
Jun 5, 2008, 5:01:10 AM6/5/08
to David Cournapeau, pytho...@python.org
> The problem is not compiler, but runtime. For example, if python is
> built with runtime foo, and yours with runtime bar, and you use in bar
> a file handle, you're screwed:
>
> http://msdn.microsoft.com/en-us/library/ms235460(VS.80).aspx
>
> That's why you cannot build a python extension with VS 2005 for python
> 2003, in a reliable way.

Thank you for providing this document. Indeed, passing internal
pointers of one CRT lib to another is dangerous. But in most cases,
the python extension only focus on computational-intensive jobs
rather than API-intensive jobs. Therefore it is safe to let VS2003-built
python to call VS2005-built extensions with some attentions.

When you use distutil to trigger compilation, a special *python script*
will check whether the default compiler is VS2003. If there is no
VS2003, this script will pop-up the error for incompatible compilers.
I really really wonder how to *force* distutil to use my specified compile.
eg: (pseudo)
python setup.py build -c VC2005
or
python setup.py build --compiler=C:\VC8\cc --linker=C:\VC8\ld

Regards,

---
ShenLei

Terry Reedy

unread,
Jun 5, 2008, 4:16:15 PM6/5/08
to pytho...@python.org

"??" <littlesw...@gmail.com> wrote in message
news:cdb837ea0806050201l10a...@mail.gmail.com...

| When you use distutil to trigger compilation, a special *python script*
| will check whether the default compiler is VS2003. If there is no
| VS2003, this script will pop-up the error for incompatible compilers.
| I really really wonder how to *force* distutil to use my specified
compile.
| eg: (pseudo)
| python setup.py build -c VC2005
| or
| python setup.py build --compiler=C:\VC8\cc --linker=C:\VC8\ld

(Completely untested suggestions ;-)
Rename VC2005 to VC2003?
Change or add the appropriate registry entry?

"Martin v. Löwis"

unread,
Jun 5, 2008, 4:36:00 PM6/5/08
to
> I really really wonder how to *force* distutil to use my specified compile.
> eg: (pseudo)

You need to make sure that both MSSdk and DISTUTILS_USE_SDK are set, see

http://docs.python.org/dist/module-distutils.msvccompiler.html

Regards,
Martin

lotrpy

unread,
Jun 11, 2008, 8:14:25 PM6/11/08
to
On 6月4日, 下午9时47分, "David Cournapeau" <courn...@gmail.com> wrote:

My stupid question: if there is something between VS 2003 and VS 2005
incompatible, what
about MINGW for python2.5(VS 2003)? Is it safe, or just as (un)safe
as VS 2005?

0 new messages