__declspec(dllexport) & __declspec(dllimport) - platformunabhängig?
-
Hallo,
Sind __declspec(dllexport) und __declspec(dllimport) platform, bzw. compilerunabhängig?Wenn nein, was ist die platformunabhängige Alternative?
-
Nö.
devkid@desktop:~$ cat so.c __declspec(dllexport) void foo () { } devkid@desktop:~$ gcc -shared so.c so.c: In Funktion »__declspec«: so.c:2: Fehler: expected »=«, »,«, »;«, »asm« or »__attribute__« before »{« token so.c:3: Fehler: expected »{« at end of input
Brauchst du bei anderen System als Windows nicht.
-
ich includiere immer in jede headerDatei das hier zuerst:
die 3 links ganz oben sind ganz sinnvoll bei sowas.Gruß
Martin
#ifndef COMPILERSETTINGS_H #define COMPILERSETTINGS_H // @see http://gcc.gnu.org/wiki/Visibility // @see http://people.redhat.com/drepper/dsohowto.pdf // @see http://www.eventhelix.com/RealtimeMantra/HeaderFileIncludePatterns.htm // Generic helper definitions for shared library support #if defined(_WIN32) || defined(__CYGWIN__) # if defined(_MSC_VER) // Windows && MS Visual C # if _MSC_VER < 1310 //Version < 7.1? # pragma message ("Compiling with a Visual C compiler version < 7.1 (2003) has not been tested!") # endif // Version > 7.1 # define MYLIB_HELPER_DLL_IMPORT __declspec(dllimport) # define MYLIB_HELPER_DLL_EXPORT __declspec(dllexport) # define MYLIB_HELPER_DLL_LOCAL # elif defined (__GNUC__) # define MYLIB_HELPER_DLL_IMPORT __attribute__((dllimport)) # define MYLIB_HELPER_DLL_EXPORT __attribute__((dllexport)) # define MYLIB_HELPER_DLL_LOCAL # endif # define BOOST_ALL_NO_LIB //disable the msvc automatic boost-lib selection in order to link against the static libs! #elif defined(__linux__) || defined(linux) || defined(__linux) # if __GNUC__ >= 4 // TODO Makefile: add -fvisibility=hidden to compiler parameter in Linux version # define MYLIB_HELPER_DLL_IMPORT __attribute__ ((visibility("default"))) # define MYLIB_HELPER_DLL_EXPORT __attribute__ ((visibility("default"))) # define MYLIB_HELPER_DLL_LOCAL __attribute__ ((visibility("hidden"))) # else # define MYLIB_HELPER_DLL_IMPORT # define MYLIB_HELPER_DLL_EXPORT # define MYLIB_HELPER_DLL_LOCAL # endif #endif // Now we use the generic helper definitions above to define MYLIB_API and MYLIB_LOCAL. // MYLIB_API is used for the public API symbols. It either DLL imports or DLL exports (or does nothing for static build) // MYLIB_LOCAL is used for non-api symbols. #ifndef MYLIB_DLL #define MYLIB_DLL #endif // TODO Makefile: add MYLIB_DLL and EXPORTS #ifdef MYLIB_DLL // defined if MYLIB is compiled as a DLL # ifdef MYLIB_DLL_EXPORTS // defined if we are building the MYLIB DLL (instead of using it) # define DLL_PUBLIC MYLIB_HELPER_DLL_EXPORT # else # define DLL_PUBLIC MYLIB_HELPER_DLL_IMPORT # endif // MYLIB_DLL_EXPORTS # define DLL_LOCAL MYLIB_HELPER_DLL_LOCAL # else // MYLIB_DLL is not defined: this means MYLIB is a static lib. # define DLL_PUBLIC # define DLL_LOCAL #endif // MYLIB_DLL // disable some nasty MSVC Warnings #ifdef _MSC_VER // Windows && MS Visual C # pragma warning( disable : 4996 ) // disable deprecation warnings //# pragma warning( disable : 4091 ) // disable typedef warning without variable declaration # pragma warning( disable : 4275 ) // non – DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier' # pragma warning( disable : 4251 ) // like warning above but for templates (like std::string) #endif #endif //COMPILERSETTINGS_H