Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OS X contains heapsort in stdlib.h which conflicts with heapsort in sort library

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?

like image 287
Hunter Avatar asked Dec 08 '25 06:12

Hunter


2 Answers

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.

like image 52
Jonathan Leffler Avatar answered Dec 10 '25 02:12

Jonathan Leffler


You can try defining _POSIX_C_SOURCE:

$ gcc -E /usr/include/stdlib.h | grep heap
int heapsort(void *, size_t, size_t,
int heapsort_b(void *, size_t, size_t,

$ gcc -E -D_POSIX_C_SOURCE /usr/include/stdlib.h | grep heap
# No output at all this time

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.

like image 24
mu is too short Avatar answered Dec 10 '25 01:12

mu is too short



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!