2015-10-20 120 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
但要注意,如果堆和堆栈重叠,则会出现问题。

相关问题