[Distutils] Compiling / Installing extensions

Thomas Heller thomas.heller@ion-tof.com
Wed, 9 Feb 2000 11:33:12 +0100


> > > > We should drop the line
> > > >     self.add_library ( "python" + sys.version[0] + sys.version[2] )
> > > > in msvccompiler.py.
> > >
> > > Absoposidefinutely yes!  I guess by my evolving standard, that should
go
> > > in the MSVC-specific code in build_ext.py.
> > It is NOT NEEDED at all!
> > The correct pythonxxx.lib will automatically be included on windows.
>
> Cool!  That's good news.  I hate to keep sounding disbelieving of you,
> but if there is a "25 words or less" explanation of why that works,
> would you mind filling me in?  (Mainly I'm curious -- if you tell me not
> to get worried about it, it's complicated but it just works, then I'll
> probably trust you.  But I *do* like to know what's going on behind the
> scenes...)
>
MSVC has a pragma which allow to specify in the C-source file
libraries to link with. Looking at config.h (from 1.5.2):
/* So nobody needs to specify the .lib in their Makefile any more */
#ifdef _DEBUG
#pragma comment(lib,"python15_d.lib")
#else
#pragma comment(lib,"python15.lib")

Quoting from MSDN:

#pragma comment( comment-type [, commentstring] )

Places a comment record into an object file or executable file. The
comment-type is one of five predefined identifiers, described below, that
specify the type of comment record. The optional commentstring is a string
literal that provides additional information for some comment types. Because
commentstring is a string literal, it obeys all the rules for string
literals with respect to escape characters, embedded quotation marks ("),
and concatenation.
[...]
lib

Places a library-search record in the object file. This comment type must be
accompanied by a commentstring parameter containing the name (and possibly
the path) of the library that you want the linker to search. Since the
library name precedes the default library-search records in the object file,
the linker searches for this library just as if you had named it on the
command line. You can place multiple library-search records in the same
source file; each record appears in the object file in the same order in
which it is encountered in the source file.

[End of quote]