When building 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 gives an error for GCC (ARM). I have found out that __declspec(dllexport) wont work on GCC. If so, what should I use for GCC (ARM)?
Edit:
Its used in many classes. e.g:
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;
};
__declspec(dllexport) adds the export directive to the object file so you do not need to use a . def file. This convenience is most apparent when trying to export decorated C++ function names.
The __declspec keyword enables you to specify special attributes of objects and functions. For example, you can use the __declspec keyword to declare imported or exported functions and variables, or to declare Thread Local Storage (TLS) objects.
__declspec The extended attribute syntax simplifies and standardizes Microsoft-specific extensions to the C and C++ languages.
The dllexport and dllimport storage-class attributes are Microsoft-specific extensions to the C and C++ languages. You can use them to export and import functions, data, and objects to or from a DLL.
Basically, you probably don't need anything special. But if you want (and if working on shared objects, i.e. *.so
files), learn more about visibility pragmas and visibility function attributes
And the question is more target operating system specific than target machine specific. (I would imagine that an ARM running some obscure Windows8/ARM system would also need your __declspec
; conversely, your __declspec
has no sense on Linux/x86).
Here's 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 code by default with -fvisibility=hidden -fvisibility-inlines-hidden
and mark up stuff we want to export with idaman
, e.g.
idaman bool ida_export set_enum_width(enum_t id, int width);
Since you're exporting C++ methods, you'll probably want to skip the extern "C"
part.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With