Undefined reference to 'strnlen' even though "string.h" includes

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 the error:

Undefined reference to 'strnlen'

      

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

I am building a Cortex-M3 processor Compiler used: arm-none-eabi-gcc In Eclipse I checked the MCU linker option: No bootable or standard libs I am running Eclipse on Ubuntu

While it might be easy enough to get around this by just using strlen, I am really running into a problem using a library that uses strnlen and I don't want to link to the library source.

+3


source to share


4 answers


The function strnlen

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



+3


source


I am adding the same problem and I found out that using a -std=gnu++11

compiler flag resolves it.



+1


source


You want to enable this instead:

#include <string.h>

      

The difference between <>

and ""

is what it <>

searches for header files on your system, including the folder. ""

looks for header files in the current directory and in any other included folders specified-I directory

0


source


The following may work for you (since strnlen () is not part of the runtime).

Define your own / local version strnlen()

.

int strnlen(char *param, int maxlen)
{  
    // Perform appropriate string manipulation ... as needed.
    // Return what you need.
};  

      

0


source







All Articles