GCC (ARM) equivalent to __declspec (dllexport)

When creating an application for x86, the following code works fine:

#if defined _WIN32 #define LIB_PRE __declspec(dllexport) #elif defined __unix__ #define LIB_PRE #else #define LIB_PRE __declspec(dllexport) #endif 

But it gives an error for GCC (ARM). I found out that __declspec (dllexport) will not work on GCC. If so, what should I use for GCC (ARM)?

Edit:

Used in many classes. eg:

 class CJsonValueString : public CJsonValue { private: jstring value; public: LIB_PRE CJsonValueString(jstring value); LIB_PRE CJsonValueString(const CJsonValueString * value); LIB_PRE jstring ToString() const; LIB_PRE int ToInt() const; LIB_PRE int64 ToInt64 () const; LIB_PRE float ToFloat () const; LIB_PRE void GetValue(jstring & str) const; }; 
+6
source share
2 answers

Basically, you probably don't need anything special. But if you want (and if you work with shared objects, i.e. *.so files), learn more about the vowels of the visibility and visibility function attributes

And the question is about a more specific operating system than a specific machine. (I would suggest that for ARM running on some obscure Windows8 / ARM system, your __declspec will also be needed, and vice versa, your __declspec does not make sense in Linux / x86).

+6
source

Here is a simplified version of what we use in our code.

 #ifdef __cplusplus #define EXTERNC extern "C" #else #define EXTERNC #endif #if defined(__NT__) // MS Windows #define idaapi __stdcall #define ida_export idaapi #if defined(__IDP__) // modules #define idaman EXTERNC #else // kernel #if defined(__X64__) || defined(__NOEXPORT__) #define idaman EXTERNC #else #define idaman EXTERNC __declspec(dllexport) #endif #endif #define ida_local #elif defined(__UNIX__) // for unix #define idaapi #if defined(__MAC__) #define idaman EXTERNC __attribute__((visibility("default"))) #define ida_local __attribute__((visibility("hidden"))) #else // Linux #if __GNUC__ >= 4 #define idaman EXTERNC __attribute__ ((visibility("default"))) #define ida_local __attribute__((visibility("hidden"))) #else #define idaman EXTERNC #define ida_local #endif #endif #endif 

On Linux / OS X, we compile all the default code with -fvisibility=hidden -fvisibility-inlines-hidden and mark the material we want to export with idaman , for example.

 idaman bool ida_export set_enum_width(enum_t id, int width); 

Since you export methods in C ++, you probably want to skip the extern "C" .

+2
source

Source: https://habr.com/ru/post/902308/


All Articles