mozilla / cubeb

Cross platform audio library
ISC License
441 stars 126 forks source link

Undeclared identifier 'strdup' compile error on Mac OS X #326

Open thoughton opened 7 years ago

thoughton commented 7 years ago

Hi,

When trying to build on Mac OS X (10.9.5) I get lots of errors like this:

src/cubeb_jack.cpp:949:29: error: use of undeclared identifier 'strdup'

I've discovered that moving:

#include <string.h>

to be above:

#define _POSIX_SOURCE

actually fixes the issue.

However, I fully admit that I've no idea what _POSIX_SOURCE means or does in this case...

What's the correct fix here?

Thanks!

djg commented 7 years ago

Hi,

Jack is a contributed backend that we don't compile for OS X which is why you're seeing this issue. I removed _POSIX_SOURCE, _BSD_SOURCE, etc on my linux box and cubeb_jack.cpp compiles without error.

As part of the POSIX standard, _POSIX_SOURCE is used to control which features are exposed by libc. Eg. man 3 strdup on Fedora Linux shows:

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

       strdup():
           _XOPEN_SOURCE >= 500
               || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
               || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE

The correct solution is likely to be to detect the presence of strdup using CMake's check_symbol_exists() function and taking appropriate action if it's not found.