有关交叉编译 c 中内置函数的警告



代码:

#include <string.h>
//Return copy of str string from index position and len length
char *StrCpy2(char *str, unsigned short index, unsigned char len)
{
    char *text;
    text = (char *)malloc(sizeof(char)*(len+1));
    if (text == NULL) return text;
    strncpy(text, str + index, len);
    text[len] = '';
    return text;
}

控制台输出与此文件和行相关:

Compiling file: String.c
arm-none-eabi-gcc -c -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffast-math -O0 -ffunction-sections -fdata-sections -Wall -Wstrict-prototypes -Wextra -std=gnu99 -g -ggdb3 -fverbose-asm -Wa,-ahlms=out/String.lst  -DSTM32F40_41xxx  -DUSE_STM324x7I_EVAL  -MD -MP -MF out/String.d -I.  -IBACnet/inc  -IBACnet/inc/objects  -Iinc  -Ilib/drivers/inc  -Ilib/eval  -IUI/inc  -IuIP/inc String.c -o out/String.o
String.c: In function 'StrCpy2':
String.c:39:2: warning: implicit declaration of function 'strncpy' [-Wimplicit-function-declaration]
  strncpy(text, str + index, len);
  ^
String.c:39:2: warning: incompatible implicit declaration of built-in function 'strncpy'
String.c:39:2: note: include '<string.h>' or provide a declaration of 'strncpy'

我感到迷茫,因为在从stm32f1移植到stm32f4以及codesourcery工具链到前沿工具链(这个(的过程中出了点问题。如您所见,我已经包括了.也许有些 #defines 不正确?也许日食或系统中的某些路径是错误的?

我几乎可以肯定,你的项目中有一个名为String.h的文件。因为你在Windows上编译它,它不够聪明,无法注意到你的String.h和工具链string.h之间的差异,所以#include <string.h>行实际上包括你的String.h,你很可能没有那个声明。

如果你在Linux上编译它,它很可能会工作,因为文件名的大小写在那里很重要。对于Windows,除了以不同的方式命名文件(尤其是标题(之外,您没有其他解决方案。就个人而言,我建议每个模块(标头 + 源(有一个全局函数,然后您可以在函数之后命名模块。所以在上面的情况下,你会有StrCpy2.hStrCpy2.c.

最新更新