Search code examples
cmacosflex-lexer

What's wrong with strndup?


I'm writing a parser using flex. I'm using Mac OS X 10.6.7. I have already include header files like this:

#include "string.h"
#include "stdlib.h"

but it says

Undefined symbols for architecture x86_64:
  "_strndup", referenced from:
      _yylex in ccl2332A.o
ld: symbol(s) not found for architecture x86_64

why?


Solution

  • AFAIK there is no method strndup in string.h or stdlib.h, try using strdup() which is probably what you want. If you really need to specifiy the length you want allocated you could do it using malloc and memcpy instead.