2015-10-20 118 views
0

我遇到了一個錯誤,無疑是由於我對連接器工作方式知識的限制。我編寫的一些ANSI C代碼在我的OS X框上編譯和鏈接完美,但在爲ARM進行交叉編譯時無法與arm-none-eabi-ld鏈接。當與arm-none-eabi-ld鏈接時未定義引用`calloc'

下面是從結果一個乾淨make(與--verboseld):

arm-none-eabi-gcc -o build/fft.o src/fft.c -g -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -Os -ffunction-sections -fdata-sections -MD -std=c99 -Wall -pedantic -DPART_TM4C123GH6PM -c -I../tivaware -DTARGET_IS_BLIZZARD_RA1 
arm-none-eabi-gcc -o build/main.o src/main.c -g -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -Os -ffunction-sections -fdata-sections -MD -std=c99 -Wall -pedantic -DPART_TM4C123GH6PM -c -I../tivaware -DTARGET_IS_BLIZZARD_RA1 
arm-none-eabi-ld -o build/a.out build/fft.o build/main.o --verbose -T TM4C123GH6PM.ld --entry main --gc-sections 
GNU ld (32-bit ARM EABI Toolchain JBS-FLOAT_IO-SGXXLITE_ML-2014.05-28-v2013.05-36-g3f93944) 2.24.51.20140217 
    Supported emulations: 
    armelf 
opened script file TM4C123GH6PM.ld 
using external linker script: 
================================================== 
MEMORY 
{ 
    FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000 
    SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0X00008000 
} 

SECTIONS 
{ 
    /* code */ 
    .text : 
    { 
     _text = .; 
     /* ensure ISR vectors are not removed by linker */ 
     KEEP(*(.isr_vector)) 
     *(.text*) 
     *(.rodata*) 
     _etext = .; 
    } > FLASH 

    /* static data */ 
    .data : AT(ADDR(.text) + SIZEOF(.text)) 
    { 
     _data = .; 
     *(vtable) 
     *(.data*) 
     _edata = .; 
    } > SRAM 

    /* static uninitialized data */ 
    .bss : 
    { 
     _bss = .; 
     *(.bss*) 
     *(COMMON) 
     _ebss = .; 
    } > SRAM 

} 

================================================== 
attempt to open build/fft.o succeeded 
build/fft.o 
attempt to open build/main.o succeeded 
build/main.o 
build/fft.o: In function `dft': 
/path/src/fft.c:97: undefined reference to `calloc' 

還有其他一些不確定的符號(__aeabi_dadd__muldc3),我已經被截斷爲簡潔。

+1

我看不到'libc.lib'或'glibc.lib'鏈接。 'calloc','muldc3'等在那裏。 – wallyk

回答

1

微控制器通常(實際的原因)沒有配置動態內存分配功能。
因此,malloc,calloc,free將不可用。

建議:使用靜態數組分配內存。

即使在讀完此代碼後,您仍需要動態內存分配,您可以使用newlibc
但要注意,如果堆和堆棧重疊,則會出現問題。

相關問題