This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH, 3/4] Enable libstdc++ as a DLL on windows platforms.


Kai Tietz wrote:

> You miss the point that VC defines _DLL automatically. This macro
> isn't user controlled. It is a builtin macro, like __FILE__, or
> _WIN32. 

Sortof.

I just ran a bunch of experiments with MSVC2005. If you use the "linker"
flags /MD, /MDd, /MT, /MTd, etc, when compiling your object files, then
what you say is true.

That is, for example
  cl /MD /Fofoo.obj foo.c
  cl /MD /Fefoo.exe foo.obj
or all-in-one
  cl /MD /Fefoo.exe foo.c

The linker flags
   /MD and /MDd
act as if they were
   "/MD /D_DLL" and "/MDd /D_DLL"
which is to say, you can override them if /U_DLL appears later on the
command line; but if /U_DLL appears before /MD or /MDd, then they win
and _DLL is defined.

The "linker" flags that don't set _DLL (like /MT or /MTd) also do not
*unset* it. So, if you explicitly say /D_DLL on the command line when
compiling your .objs then it doesn't matter where on the command line
you say it: _DLL will be defined.

What's interesting is if you don't use the "linker" flags at all when
compiling:

cl /Fofoo.obj foo.c
cl /MD /Fefoo.exe foo.obj

then _DLL is *not* defined (even tho you are linking successfully
against the DLL).  So, conceivably, projects could do this:

cl /D_DLL /D_MT /Fomy_object my_source
cl /MD /Fomy_exe my_objects

and have explicit control over these so-called "automatic" macros.  But
that's not the "typical" way you do things with the MS compiler. Usually
you *do* use the the "linker" flags when compiling objects, and let the
compiler worry about the internal details of defining/undefining _DLL,
_MT, _DEBUG, etc.

> The problem occurs, when users want to include headers from a
> library using _DLL for making decisions about dllimport or static API.

But the issue here is, how likely is it that anyone will try to use
GCC's libstdc++ and its headers from MSVC?  That's not possible, is it?

Sure, maybe it's a bad idea for, say, libpng to use _DLL as the "magic"
macro controlling symbol decoration -- but the reasoning doesn't hold
for a compiler-specific library like libstdc++ or libgcc.

--
Chuck

#include <stdio.h>
int main(int argc, char** argv)
{
#ifdef _DLL
  puts("_DLL is defined\n");
#else
  puts("_DLL is not defined\n");
#endif
  return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]