00001 /* Filename: dtoolsymbols.h 00002 * Created by: drose (18Feb00) 00003 * 00004 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00005 * 00006 * PANDA 3D SOFTWARE 00007 * Copyright (c) Carnegie Mellon University. All rights reserved. 00008 * 00009 * All use of this software is subject to the terms of the revised BSD 00010 * license. You should have received a copy of this license along 00011 * with this source code in a file named "LICENSE." 00012 * 00013 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00014 00015 #ifndef DTOOLSYMBOLS_H 00016 #define DTOOLSYMBOLS_H 00017 00018 00019 /* 00020 This file defines a slew of symbols that have particular meaning 00021 only when compiling in the WIN32 environment. These symbols are 00022 prefixed to each class declaration, and each global function, that 00023 is to be made visible outside of a DLL. 00024 00025 The problem is that in Windows, you must prefix each DLL-public 00026 symbol with "__declspec(dllexport)" when you are compiling the DLL, 00027 but with "__declspec(dllimport)" when you are compiling code that 00028 links with the DLL. This strange convention means that you must, in 00029 principle, have two different .h files for a DLL: one to use for 00030 compiling the DLL (it must export all of the symbols), and a 00031 different one for presenting the public interface for other users to 00032 use (it must import all of the same symbols). 00033 00034 In practice, of course, maintaining two different .h files is silly 00035 and error-prone; almost everyone solves this problem by defining a 00036 macro that evaluates to "__declspec(dllexport)" in one case and 00037 "__declspec(dllimport)" in another case. Many systems use the 00038 system macro _DLL to switch between these two case, which works well 00039 in a simple system because _DLL is defined only if compiler is 00040 currently generating code for a DLL. So you can export the symbols 00041 if _DLL is defined, and import them if it is not defined. 00042 00043 However, this fails if you are compiling a DLL that wants to import 00044 symbols from another DLL, since in this case _DLL is defined, but 00045 the symbols in the other DLL need to be imported, not exported. 00046 00047 In the general case of compiling multiple DLL's that might reference 00048 each other's symbols, we need have a separate macro for each DLL. 00049 Then when we are compiling code for each DLL, the macro for that 00050 particular DLL evaluates to "__declspec(dllexport)", exporting all 00051 the symbols from the DLL, while all the other DLL's macros evaluate 00052 to "__declspec(dllimport)", importing all the symbols from the other 00053 DLL's. 00054 00055 That is the approach we have taken here in Panda. When we are 00056 compiling code for a particular DLL, the build scripts define the 00057 macro BUILDING_libname on the command line. This file then uses 00058 that macro to define EXPCL_libname appropriately for each DLL; this 00059 macro is then used to prefix each symbol to be exported from the 00060 DLL. The macro name stands for "export class", since it is used 00061 most often to mark a class for export, although the same macro can 00062 be used to export global functions. (We also define EXPTP_libname, 00063 which is used in conjunction with exporting template instantiations, 00064 another dicey task in Windows. It is used far less often.) 00065 00066 Of course, this whole thing only matters under WIN32. In the rest 00067 of the world we don't have to deal with this nonsense, and so we 00068 can define all of these stupid symbols to the empty string. 00069 */ 00070 00071 #define EXPCL_EMPTY 00072 00073 #if defined(WIN32_VC) && !defined(CPPPARSER) && !defined(LINK_ALL_STATIC) 00074 00075 #ifdef BUILDING_DTOOL 00076 #define EXPCL_DTOOL __declspec(dllexport) 00077 #define EXPTP_DTOOL 00078 #else 00079 #define EXPCL_DTOOL __declspec(dllimport) 00080 #define EXPTP_DTOOL extern 00081 #endif 00082 00083 #ifdef BUILDING_DTOOLCONFIG 00084 #define EXPCL_DTOOLCONFIG __declspec(dllexport) 00085 #define EXPTP_DTOOLCONFIG 00086 #else 00087 #define EXPCL_DTOOLCONFIG __declspec(dllimport) 00088 #define EXPTP_DTOOLCONFIG extern 00089 #endif 00090 00091 #ifdef BUILDING_MISC 00092 #define EXPCL_MISC __declspec(dllexport) 00093 #define EXPTP_MISC 00094 #else /* BUILDING_MISC */ 00095 #define EXPCL_MISC __declspec(dllimport) 00096 #define EXPTP_MISC extern 00097 #endif /* BUILDING_MISC */ 00098 00099 #else /* !WIN32_VC */ 00100 00101 #define EXPCL_DTOOL 00102 #define EXPTP_DTOOL 00103 00104 #define EXPCL_DTOOLCONFIG 00105 #define EXPTP_DTOOLCONFIG 00106 00107 #define EXPCL_MISC 00108 #define EXPTP_MISC 00109 00110 #endif /* WIN32_VC */ 00111 00112 #endif