Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implicit declaration of function basename in linux

Tags:

c

warnings

i am using basename() function in my code. Where i am including

#include <unistd.h>

and when i m compiling that code with -Wall flag it shows

following warning

warning: implicit declaration of function ‘basename’

if i am writing its declaration in my code

char * basename (const char *fname);

then it does not show that warning

why this happening.?

like image 534
Jeegar Patel Avatar asked Jan 17 '26 22:01

Jeegar Patel


2 Answers

You need to include <libgen.h>.

The standard says it's in libgen.h, kernel.org does so too.

like image 104
cnicutar Avatar answered Jan 19 '26 19:01

cnicutar


If you look at the man page for basename:

man 3 basename

You'll see that you need to include libgen.h to get the prototype for basename (and similar function dirname):

#include <libgen.h>

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!