Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to `strnstr' how to fix it and run strnstr [closed]

Tags:

c

gcc

string.h

I need to reproduce behavior of strnstr function. I want to test strnstr but can't compile program, its written "implicit declaration of function strnstr [-Wimplicit-function-declaration]" and "undefined reference to strnstr". I included header <string.h>.

I know that strnstr() isn't in standard library and the problem is probably connected with compiler, but how to fix it to work with strnstr()?

Compiler version: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609

like image 254
ivoriik Avatar asked Oct 22 '25 19:10

ivoriik


1 Answers

There's no function named strnstr in standard C or POSIX. It's not in glibc/Linux either. It appears to be FreeBSD function.

I know that strnstr() isn't in standard library and the problem is probably connected with compiler, but how to fix it to work with strnstr()?

Not sure why you think it's a compiler issue (unless you think it's a compiler intrinsic). If it's not provided by your C library, it's just not available.

So if it's not available on your system (probably you are not using a BSD system) then you can implement it. You can look at an existing implementation.

like image 90
P.P Avatar answered Oct 24 '25 10:10

P.P



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!