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

"warning: implicit declaration of function ‘random’" message when compiling #15

Open
abetusk opened this issue Nov 19, 2020 · 0 comments

Comments

@abetusk
Copy link

abetusk commented Nov 19, 2020

When I compile, I get the following warning:

$ make clean ; make
rm -rf smaz_test
gcc -o smaz_test -O2 -Wall -W -ansi -pedantic smaz.c smaz_test.c
smaz_test.c: In function ‘main’:
smaz_test.c:58:18: warning: implicit declaration of function ‘random’ [-Wimplicit-function-declaration]
         ranlen = random() % 512;

The program compiles and the tests pass, so it looks like this warning is non-critical.

From looking around, I found an SO question/answer that offers a solution.

Adding the -D_XOPEN_SOURCE=600 option to gcc in the Makefile fixes the issue for me:

$ git diff
diff --git a/Makefile b/Makefile
index 62e8ccb..eecbac7 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 all: smaz_test
 
 smaz_test: smaz_test.c smaz.c
-       gcc -o smaz_test -O2 -Wall -W -ansi -pedantic smaz.c smaz_test.c
+       gcc -D_XOPEN_SOURCE=600 -o smaz_test -O2 -Wall -W -ansi -pedantic smaz.c smaz_test.c
 
 clean:
        rm -rf smaz_test

My system information:

$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

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