本文介绍了在Mac OSX上导出DLL函数的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Mac OS X 10.6上编译一个简单的DLL,并且对声明该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)

,但是上面有gcc barfs。示例代码实际包含的是MACPASCAL和DLLExport,我认为它们是宏。我为#define遍历了示例代码,SDK等,并插入了我发现的内容。这些定义可能被埋在#ifs内,所以我发现这是不好的和真实的。从逻辑上讲,如果我只是做显而易见的事情并且使用DLLExport和MACPASCAL,编译器也会拒绝使用,因此这不是解决方案。

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.

什么是使DLL函数可用的正确方法是什么?应用?

What is the correct way to make a DLL's function available to apps?

推荐答案

默认情况下,所有符号都在 .dylib 中可见。通话惯例没有更改(例如Pascal通话惯例)

By default, all symbols are visible in a .dylib. There are no calling convention changes (such as Pascal calling convention)

因此,简而言之:

int ReturnTheNunmberFive(void){return 6; }

这篇关于在Mac OSX上导出DLL函数的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 07:38