Correct way to export a DLL function on Mac OSX

2019-06-08 14:46发布

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?

1条回答
迷人小祖宗
2楼-- · 2019-06-08 15:31

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; }

查看更多
登录 后发表回答