Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC (ARM) equivalent to __declspec(dllexport)

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;
};
like image 215
umair Avatar asked Nov 24 '11 14:11

umair


People also ask

What is __ Declspec Dllexport?

__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.

What is __ Declspec in C ++?

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.

What does __ Declspec do?

__declspec The extended attribute syntax simplifies and standardizes Microsoft-specific extensions to the C and C++ languages.

What is Dllexport?

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.


2 Answers

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).

like image 70
Basile Starynkevitch Avatar answered Sep 21 '22 21:09

Basile Starynkevitch


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.

like image 36
Igor Skochinsky Avatar answered Sep 20 '22 21:09

Igor Skochinsky