是否有与 Linux 等效的 __declspec(dllexport)
表示法用于从共享库中显式导出函数?由于某种原因,我正在使用的工具链中,非类成员的函数不会出现在生成的共享库文件中。
最佳答案
__attribute__((visibility("default")))
据我所知,没有与 __declspec(dllimport)
等效的东西。
#if defined(_MSC_VER)
// Microsoft
#define EXPORT __declspec(dllexport)
#define IMPORT __declspec(dllimport)
#elif defined(__GNUC__)
// GCC
#define EXPORT __attribute__((visibility("default")))
#define IMPORT
#else
// do nothing and hope for the best?
#define EXPORT
#define IMPORT
#pragma warning Unknown dynamic link import/export semantics.
#endif
典型用法是定义像 MY_LIB_PUBLIC
这样的符号,有条件地将其定义为 EXPORT
或 IMPORT
,具体取决于库当前是否正在运行编译与否:
#if MY_LIB_COMPILING
# define MY_LIB_PUBLIC EXPORT
#else
# define MY_LIB_PUBLIC IMPORT
#endif
要使用它,你可以像这样标记你的函数和类:
MY_LIB_PUBLIC void foo();
class MY_LIB_PUBLIC some_type
{
// ...
};
https://stackoverflow.com/questions/2164827/
相关文章:
linux - 在 bash 脚本中使用 curl 并获取 curl : (3) Illegal c
c++ - 在 64 位 Linux 操作系统上编译 32 位程序导致 fatal error
python - 如何从 subprocess.Popen() 获取输出。 proc.stdout.
linux - 如何获取自上次使用 bash 修改文件以来的时间(以秒为单位)?
linux - 是否可以使用 shell 脚本递归地创建文件夹?
linux - 为什么使用 dd 克隆磁盘时使用 conv=notrunc?
linux - shell 脚本 : Run function from script over s