2
代码:警告交叉编译的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] = '\0';
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 toolchain到bleeding-edge-toolchain (this one)。正如你所看到的,我已经包含了。也许一些#定义不正确?也许在日食或系统中的某些路径是错误的?
听起来好像'strncpy'没有在另一个工具链的'string.h'中定义。您可以通过检查'string.h'文件来轻松检查。 –
在您的IDE路径下(通常位于名为'“include”'的文件夹中)查找名为'“string.h”'的所有文件。在每个文件中搜索'strncpy'。听起来就像你在stm32f1项目中包含的那样声明了这个函数,但是你在stm32f4项目中包含的那个不会。最后,在您的stm32f4项目设置中,将您的'include'路径更改为与stm32f1项目设置中相同的路径。 –
你确定'string.h'中有'strncpy'声明吗?它应该在那里,但也许你正在使用一些过时的工具链或其他东西。无论如何,你可以自己写这个函数,这并不难。 – ForceBru