Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mac OS] error: implicitly declaring library function 'strdup' #3

Open
bogdan0083 opened this issue Feb 28, 2024 · 0 comments
Open

Comments

@bogdan0083
Copy link

bogdan0083 commented Feb 28, 2024

Hi! 👋

I'm having issue building the sph2pipe on Mac OS Sonoma and Xcode 15. Here are the errors:

cc -o sph2pipe -s -w -g -O2  file_headers.c shorten_x.c sph2pipe.c -lm
file_headers.c:100:17: error: call to undeclared library function 'strdup' with type 'char *(const char *)'; ISO C99 and later do not support i
mplicit function declarations [-Wimplicit-function-declaration]
            inporder = strdup( fldsval );
                       ^
file_headers.c:100:17: note: include the header <string.h> or explicitly provide a declaration for 'strdup'
1 error generated.
sph2pipe.c:213:16: error: call to undeclared library function 'strdup' with type 'char *(const char *)'; ISO C99 and later do not support impli
cit function declarations [-Wimplicit-function-declaration]
            hdrfile = strdup( optarg );
                      ^

Here's similar issue in other project. They fixed it by defining _DARWIN_C_SOURCE. Like this:

file_headers.c:

#define _XOPEN_SOURCE 500  /* See feature_test_macros(7) */
#define _DARWIN_C_SOURCE
#include <math.h>
#include <string.h>
#include <unistd.h>

/* code goes on ... */

sph2pipe.c:

#define _SPH_CONVERT_MAIN_
#define _XOPEN_SOURCE 500  /* See feature_test_macros(7) */
#define _DARWIN_C_SOURCE
#include <string.h>
#include <unistd.h>

/* code goes on ... */

I might send PR if you are interested in fixing it. I'm not very proficient in C code and don't know if those changes could break anything, but I can confirm that the changes are working. After adding those headers code builds just fine.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant