Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use strcasestr()?

Tags:

c

string

gcc

I #include <string.h> but when I call strcasestr(src, search); I get the following error message implicit declaration of function ‘strcasestr’. how to I compile: gcc-4.6 -Wall -lsqlite3 -lunac -Werror -O2 -o foo.out foo.c how to fix this? Thanks in advance.

like image 641
Jack Avatar asked Mar 30 '12 00:03

Jack


1 Answers

As specified in the corresponding manpage, since strcasestr is a nonstandard extension you must #define _GNU_SOURCE before the #include <string.h> before any #include (other files may already include <string.h>, thanks @Cubbi for pointing out this potential problem); this can also easily be accomplished by specifying -D_GNU_SOURCE on the compiler command line.

like image 99
Matteo Italia Avatar answered Sep 21 '22 11:09

Matteo Italia