uma*_*air 7 c++ gcc arm visual-studio-2010 dllexport
在为x86构建应用程序时,以下代码可以正常工作:
#if defined _WIN32
#define LIB_PRE __declspec(dllexport)
#elif defined __unix__
#define LIB_PRE
#else
#define LIB_PRE __declspec(dllexport)
#endif
Run Code Online (Sandbox Code Playgroud)
但是给GCC(ARM)一个错误.我发现__declspec(dllexport)不适用于GCC.如果是这样,我应该为GCC(ARM)使用什么?
编辑:
它用于很多类.例如:
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;
};
Run Code Online (Sandbox Code Playgroud)
这是我们在代码中使用的简化版本。
#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
Run Code Online (Sandbox Code Playgroud)
在 Linux/OS X 上,我们默认使用 编译所有代码,并使用-fvisibility=hidden -fvisibility-inlines-hidden标记我们想要导出的内容idaman,例如
idaman bool ida_export set_enum_width(enum_t id, int width);
Run Code Online (Sandbox Code Playgroud)
由于您要导出 C++ 方法,因此您可能需要跳过这一extern "C"部分。