To avoid a whole bunch of strdup
errors, I have to always include -D_BSD_SOURCE
in my compile statement. Is there a way I can somehow include this in my .c
file and never include it in my compile statement again.
Asked
Active
Viewed 328 times
0

Jonathan Leffler
- 730,956
- 141
- 904
- 1,278

Brandon
- 401
- 5
- 20
-
I don't think `strdup` requires `_BSD_SOURCE`, does it? – user253751 Feb 03 '16 at 03:16
-
@immibis: It requires *some* feature test macro. It's not defined by ISO C. The man page on my system lists half a dozen relevant macros. – Keith Thompson Feb 03 '16 at 03:29
-
In many ways, you're not giving us very much context to work with. What platform are you on? Which compiler are you using? Which options (other than `-D_BSD_SOURCE`) are you using? Since `strdup()` is part of POSIX, you can often get what you want by `-D_XOPEN_SOURCE=700` or something similar, or the equivalent in a header file. You can often avoid the problem by compiling with GCC (or clang) and `-std=gnu11` instead of `-std=c11`. I use a header `posixver.h` which defines `_XOPEN_SOURCE` and include that first. YMMV — but we'd be able to help you better if you gave us more information. – Jonathan Leffler Feb 03 '16 at 04:14
-
Note that on some platforms, `-D_GNU_SOURCE` will work as well. – Jonathan Leffler Feb 03 '16 at 04:16
1 Answers
2
At the top of your .c file, before the includes, put this:
#define _BSD_SOURCE

dbush
- 205,898
- 23
- 218
- 273