see comments inline.
Guy Harris wrote:
On Mon, May 03, 2004 at 03:56:34AM +0200, Lars Roland wrote:
Good idea, much cleaner and less ifdef's . I decided to use config.h. I
added appropriate code to config.h.win32 in main dir and in epan. But I
don't know where to put it for non MSVC users. Probably somewhere in
"configure.in".
We could, although that's a little bit tricky - it'd have to arrange
that the appropriate #if be put into the config.h file.
No #if statements for non MSVC users: We just need a
"#define ETH_VAR_IMPORT export" in config.h. Nothing else.
For MSVC++, could Makefile.nmake's used to build .dlls define
ETH_VAR_IMPORT as "__declspec(dllimport) extern" if we're building a
libethereal DLL and as "extern" otherwise, and Makefile.nmake's not used
to build .dlls define it as "extern"?
I thought of that at first, too. But it s problematic in the root src
dir, as we have code that goes into libethereal ( the dissectors and
their helpers) and code that stays outside (e.g. tethereal specific code).
(That'd work, I think, only if no Ethereal shared library's source code
includes headers for any other Ethereal shared library - if it does,
then the headers for the shared library being built needs not to have
the "dllimport" and the headers for other shared libraries presumably
*do* need to have it. How *are* you supposed to handle that with
MSVC++? The page at
http://www.redhat.com/docs/manuals/enterprise/RHEL-3-Manual/gnu-linker/win32.html
appears to explicitly indicate that this is ugly:
This complicates the structure of library header files, because
when included by the library itself the header must declare the
variables and functions as dllexport, but when included by
client code the header must declare them as dllimport. There
are a number of idioms that are typically used to do this; often
client code can omit the __declspec() declaration completely.
See -enable-auto-import and automatic data imports for more
imformation[sic].)
This is addressed by "_NEED_VAR_IMPORT_". If "_NEED_VAR_IMPORT_" is
defined, we compile source that needs "__declspec(dllimport) export". If
it is not defined "export" has to be used. "__declspec(dllexport)"
should be used only at the definition, not at the declaration in the
header file. However MSVC will add automatically "__declspec(dllexport)"
for all symbols that are defined in the "def"-file.
For builds that use the configure script, perhaps the Makefile.am files
could use if's (similar to, for example, what's done with HAVE_PLUGINS)
to control whether to define ETH_VAR_IMPORT as "__declspec(dllimport)
extern" or just "extern". They'd have to test whether
1) we're on Windows (is "__declspec(dllimport)" required for
MinGW *and* Cygwin, or just one of them, or neither of them?)
and
2) whether we're building a dynamically-linked libethereal.
AFAIK __declspec(xxx) is MSVC specific and is not necessary for gcc
(including Cygwin). I am not sure about MinGW.
Regards,
Lars