OS X 在 stdlib.h 中包含堆排序,这与排序库中的堆排序冲突
我正在使用 Ariel Faigon 的排序库,可以在这里找到: http://www.yendor.com/programming/sort/
我能够得到所有我的代码在 Linux 上运行,但不幸的是,当尝试在 Mac 上使用 GCC 进行编译时,其默认的 stdlib.h 包含另一个堆排序,这不幸地导致了冲突类型错误。
这是 Apple 堆排序的手册页: http://developer.apple。 com/library/mac/#documentation/Darwin/Reference/ManPages/man3/heapsort.3.html
注释掉排序库标头中的堆排序会导致一大堆问题。 (请原谅双关语)
我还短暂地想过注释掉我对 stdlib.h 的使用,但我使用 malloc 和 realloc,所以这根本不起作用。
有什么想法吗?
I'm using Ariel Faigon's sort library, found here:
http://www.yendor.com/programming/sort/
I was able to get all my code working on Linux, but unfortunately, when trying to compile with GCC on Mac, its default stdlib.h contains another heapsort, which unfortunately results in a conflicting types error.
Here's the man page for Apple heapsort:
http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/heapsort.3.html
Commenting out the heapsort in the sort library header causes a whole heap of problems. (pardon the pun)
I also briefly thought of commenting out my use of stdlib.h, but I use malloc and realloc, so that won't work at all.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 Ariel Faigon 函数的使用隔离在一个小文件中,无需使用
。确保在标准 C 库之前链接 Ariel Faigon 的库。Isolate your use of Ariel Faigon's function in a single, tiny file that does not need to use
<stdlib.h>
. Make sure you link Ariel Faigon's library before the standard C library.您可以尝试定义
_POSIX_C_SOURCE
:希望
_POSIX_C_SOURCE
不会抑制您需要的任何内容。您通常可以通过
_POSIX_C_SOURCE
、_BSD_SOURCE
、_XOPEN_SOURCE
、_KEEP_YOUR_STUPID_EXTENSIONS_OUT_OF_STANDARD_HEADERS
、. .. 有时他们会互相争斗,所以你只能采用 Jonathan Leffler 建议的源分区方案。You can try defining
_POSIX_C_SOURCE
:Hopefully
_POSIX_C_SOURCE
won't suppress anything that you need.You can often get around these sorts of problems with some combination of
_POSIX_C_SOURCE
,_BSD_SOURCE
,_XOPEN_SOURCE
,_KEEP_YOUR_STUPID_EXTENSIONS_OUT_OF_STANDARD_HEADERS
, ... Sometimes they fight each other though so you're left with source partitioning schemes as Jonathan Leffler suggests.