strcasestr and strlcpy implicit declaration of function

Asked by Dragos GALALAE

I am currently developing a custom firmware for a barebone KL25Z128 MCU from Freescale.

In my project I use strcasestr for comparing some strings and strlcpy for copying some flash stored strings to RAM buffer.

Even though I have included <string.h>, where those functions should be, I get the warnings "implicit declaration of function 'strcasestr' [-Wimplicit-function-declaration]" and "implicit declaration of function 'strlcpy' [-Wimplicit-function-declaration]".

The compiler is called in the following manner:

<<< arm-none-eabi-gcc -I"C:\GNU Tools ARM Embedded\4.7 2013q3\arm-none-eabi\include" -I"<DIR>" -Os -ffunction-sections -fdata-sections -funsigned-bitfields -funsigned-char -fshort-enums -g3 -gdwarf-2 -fverbose-asm -gstrict-dwarf -Wall -c -fmessage-length=0 -mthumb -mcpu=cortex-m0plus -std=c99 -Wa,-aln=monitor_gsm_sas.lst -MMD -MP >>>

The linker is called in the following manner:

<<< arm-none-eabi-gcc -nostartfiles -static -L"C:\GNU Tools ARM Embedded\4.7 2013q3\arm-none-eabi\lib\armv6-m" -L"<DIR>" --specs=nano.specs --specs=rdimon.specs -Wl,--gc-sections,-TMKL25Z128.ld -mthumb -mcpu=cortex-m0plus -Xlinker -Map=<file>.map -o "<file>.elf" -lc_s -lg_s -lrdimon >>>

What is wrong?

Question information

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Dragos GALALAE (gala-dragos) said :
#1

I have change the C language dialect from c99 to gnu99 and the warning disappeared. Why ?

Revision history for this message
Terry Guo (terry.guo) said :
#2

I think those are not standard C library functions. They are created to avoid flaws of those standard C library functions. More explanations can be found at http://en.wikibooks.org/wiki/C_Programming/C_Reference/nonstandard/strlcpy.

Revision history for this message
Dragos GALALAE (gala-dragos) said :
#3

Yet when the language dialect was changed to gnu99 the functions have magically become standard. Since no linker error occurs, they the functions are implemented in the library.

I can't understand this behavior. If a function is present and called correctly then it should not emit any warning during compile.

Revision history for this message
Terry Guo (terry.guo) said :
#4

The background is that not all people are satisfied to put functions like strlcpy into C standard library. So different systems have their own strlcpy functions which certainly are implemented in different ways. Please be noted that there is no standard implementation of strlcpy function.

When you compile your project with -std=c99, the explicit declaration of strlcpy is removed, the symbol of stlcpy becomes a weak symbol. It gives you a chance to implement your own version strlcpy to override the one implemented by library (here is newlib). If you don't have your own strlcpy, the one from newlib will be used then.

When you use option -std=gnu99, it indicates you are going to use the functions from newlib. There is no chance for you to use your own strlcpy. If you are trying to do so, you will run into multiple definition error.

Revision history for this message
Terry Guo (terry.guo) said :
#5

When you use -std=gnu99, the string.h from newlib will explicitly declare the function strlcpy which then becomes a strong symbol.

Can you help with this problem?

Provide an answer of your own, or ask Dragos GALALAE for more information if necessary.

To post a message you must log in.