[Expat-discuss] Re: using expat as a static library

Fred L. Drake, Jr. fdrake@acm.org
Mon Jul 8 09:21:10 2002


Nick Lehman writes:
 > I think the issue is the preprocessor tests for defining XMLPARSEAPI
 > in xmlparse.[ch] is always  __declspec(dllimport) type __cdecl on windows.
 > I think this produces dll mangled names thats why you get __imp__ stuff
 > prepended on the symbol names.  I hacked those definitions in my copy
 > of 1.95.3 so they looked like the unix definitions meaning just "type"
 > which is actually __cdecl unless your using /Gz(stdcall) /Gr(fastcall).

I think the __cdecl should be kept for Windows in either case.  The
only time anyone should even consider changing that is if they are
embedding the sources in their project and can ensure that everything
is set up properly.  For a generally usable library (my concern),
__cdecl seems to be required.

 > So the current windows code path builds dll mangled names no matter what.
 > So even though you think you've got a legit static link libary you don't.
 > And you don't find out until you link your application.  Anyhow the end
 > result is the current windows code path can only really build dll's because
 > the symbols are named something you're not expecting.  I haven't actually
 > thought throuh how to make a general fix but all I did to get my test to
 > link was:

I'm not sure what the right way to deal with the DLL name mangling on
Windows is, and I don't have my Windows box available at the moment.

For xmlparse.c, perhaps the "right" thing is to change the definition
of XMLPARSEAPI from:

#define XMLPARSEAPI(type) __declspec(dllexport) type __cdecl

to:

#ifndef XMLPARSEAPI
#ifdef _DLL
#define XMLPARSEAPI(type) __declspec(dllexport) type __cdecl
#else
#define XMLPARSEAPI(type) type __cdecl
#endif
#endif

What to do about the header I really don't know -- how would a Windows
developer normally indicate that a particular library is being used in
a static or dynamic form?  Without being able to deal with that, I'm
not sure it makes sense to only change xmlparse.c.

(I'm not sure that the second definition in xmlparse.c is ever needed;
does anyone have a platform on which it is?  If it's never used, I'd
like to remove it.  The Microsoft docs don't seem to suggest that
__declspec can be tested using #ifdef.)


  -Fred

-- 
Fred L. Drake, Jr.  <fdrake at acm.org>
PythonLabs at Zope Corporation