6

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Homunculus Reticulli
  • 65,167
  • 81
  • 216
  • 341

2 Answers2

17

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

Roman Dmitrienko
  • 3,375
  • 3
  • 37
  • 48
  • That is strange ... they are declared in `/usr/include/string.h` on my system (Ubuntu 12.0.4) – Homunculus Reticulli Dec 27 '12 at 06:13
  • But they are hidden under `#ifdef __USE_BSD` macro. man page says one should include `strings.h` – Roman Dmitrienko Dec 27 '12 at 06:18
  • Yes, thanks, I just spotted that they are curently #def'ed out (first thing I should have checked really). However, according to this: http://stackoverflow.com/questions/4291149/difference-between-string-h-and-strings-h, strings.h is largely deprecated (opposite of what you say) - can you elaborate?. – Homunculus Reticulli Dec 27 '12 at 06:23
  • I'm not really sure. Both POSIX and man pages definitely suggest using `strings.h`. So I'd stick to them for now. – Roman Dmitrienko Dec 27 '12 at 06:32
  • Also, you may take a look at this discussion: http://web.archiveorange.com/archive/v/VBuN9LReKLUd3PAUqGT0 – Roman Dmitrienko Dec 27 '12 at 06:35
1

Include the header strings.h instead of string.h.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Raghu Srikanth Reddy
  • 2,703
  • 33
  • 29
  • 42