在 Mac OSX 上导出 DLL 函数的正确方法
我正在尝试在 Mac OS X 10.6 上编译一个简单的 DLL,并且对声明 DLL 提供给全世界使用的函数的正确方法感到困惑。根据可靠来源的示例代码,我想出了:
__declspsec(dllexport) pascal int ReturnTheNumberFive(void)
but gcc barfs on it.示例代码实际上有 MACPASCAL 和 DLLExport,我认为它们是宏。我在示例代码、SDK 等中查找了#defines,并插入了我找到的内容。这些定义可能被隐藏在 #ifs 中,所以我发现的不是好的和真实的。不合逻辑的是,如果我只做显而易见的事情并使用 DLLExport 和 MACPASCAL,编译器也会报错,所以这不是解决方案。
使 DLL 的函数可供应用程序使用的正确方法是什么?
I'm trying to compile a simple DLL on a Mac OS X 10.6, and am confused about the proper way to declare a function that the DLL offers up for the world to use. Following sample code from a reliable source, I came up with:
__declspsec(dllexport) pascal int ReturnTheNumberFive(void)
but gcc barfs on it. What the sample code actually had was MACPASCAL and DLLExport, which I assumed were macros. I grepped through the sample codes, SDKs, etc for #defines and plugged in what I found. These definitions could have been buried inside #ifs, so what I found isn't good and true. Illogically, the compiler also barfs if I just do the obvious and use DLLExport and MACPASCAL, so that's no solution.
What is the correct way to make a DLL's function available to apps?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,所有符号在
.dylib
中可见。没有调用约定更改(例如 Pascal 调用约定)因此,简而言之:
int ReturnTheNunmberFive(void) { return 6; }
By default, all symbols are visible in a
.dylib
. There are no calling convention changes (such as Pascal calling convention)So, in short:
int ReturnTheNunmberFive(void) { return 6; }