Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined reference to 'strnlen' despite "string.h" include

Tags:

c

gcc

eclipse

arm

lpc

I am trying to use create a project for LPC1769 on LPCXpresso. I have a C file calling

#include <string.h>
int main()
{
    //some stuff
    strnlen(SomeString, someInt);
}

to which I get an error:

Undefined reference to 'strnlen'

The weird part is that there is no problem with strcpy, strncpy or other common string functions.

I am building for a Cortex-M3 processor Compiler used is: arm-none-eabi-gcc In Eclipse, I have ticked the MCU linker option : No startup or default libs I am running Eclipse on Ubuntu

While it may be easy enough to bypass this by just using strlen, I am actually facing a problem using a library which uses strnlen, and I don't want to mess with the library source.

like image 361
TSG Avatar asked May 13 '15 00:05

TSG


1 Answers

The strnlen function was (until fairly recently) a Linux-specific function (some documentation such as the GNU libc manual still says that it is a "GNU extension"). The current manual page says it is part of POSIX.1-2008. Since you are cross-compiling, it is possible that the target machine's runtime library does not have this function. A forum posting from 2011 said just that.

like image 52
Thomas Dickey Avatar answered Sep 30 '22 22:09

Thomas Dickey