Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

implicit declaration of function ‘str[n]casecmp’ [-Werror=implicit-function-declaration]

Tags:

c

gcc

c99

I am compiling a C library, using C99. I am including string.h to my translation unit (and I can navigate to the definitions of the str?casecmp functions in my netbeans IDE.

The source looks something like this:

#include <string.h>

int foo(char* c1, char* c2) {
   return strcasecmp(c1, c2);
}


int foobar(char* c1, char* c2, int n) {
   return strncasecmp(c1, c2, n);
}

However, when I attempt to compile, I get the error shown in the title.

I am using gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5).

This is what my gcc command looks like:

gcc    -c -g -Werror -DE4C_THREADSAFE -DLINUX_BUILD -I../include -I../genutils -std=c99 -fPIC  -MMD -MP -MF build/Debug/GNU-Linux-x86/btypes.o.d -o build/Debug/GNU-Linux-x86/btypes.o btypes.c

What is causing this, and how do I fix it?

like image 254
Homunculus Reticulli Avatar asked Dec 27 '12 06:12

Homunculus Reticulli


People also ask

What is implicit declaration of function?

If a name appears in a program and is not explicitly declared, it is implicitly declared. The scope of an implicit declaration is determined as if the name were declared in a DECLARE statement immediately following the PROCEDURE statement of the external procedure in which the name is used.

How do you fix an implicit function declaration?

Function name typo: Often the function name of the declaration does not exactly match the function name that is being called. For example, startBenchmark() is declared while StartBenchmark() is being called. I recommend to fix this by copy-&-pasting the function name from the declaration to wherever you call it.

What is implicit function declaration error in C?

implicit declaration of function. So what does the gcc warning 'implicit declaration of function' mean (other compiler report a 'implicit parameter declaration')? Basically it means that the compiler has found a call to function for which he does not have a prototype.


1 Answers

These functions are declared in strings.h, not string.h.

like image 64
Roman Dmitrienko Avatar answered Sep 26 '22 22:09

Roman Dmitrienko