GCC (ARM) equivalent to __declspec(dllexport)

10,751

Solution 1

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

Solution 2

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.

Share:
10,751
umair
Author by

umair

Updated on June 11, 2022

Comments

  • umair
    umair almost 2 years

    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;
    };
    
  • rubenvb
    rubenvb over 12 years
    Exaclty, Windows 8 probably also uses such attributes for ARM. I don't see why they wouldn't :)
  • Basile Starynkevitch
    Basile Starynkevitch over 12 years
    In my very biased opinion, Windows design of DLLs is much worse than Linux shared libraries.
  • rubenvb
    rubenvb over 12 years
    I personally like the explicit visibility MS enforces. It allows for a clean interface, although stuff like MYLIB_DLL defines pop up in the wild :/
  • Sam Ginrich
    Sam Ginrich over 2 years
    In MINGW / GCC __declspec and visiblity pragmas can both occur, where the use of __declspec seems to suppress the visbility pragma, such that if one third party lib requires __declspec, all shall have it