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