2013-01-10 95 views
1

我正在使用Eclipse爲ARM處理器交叉編譯g ++項目。我在Windows環境中使用yagarto工具鏈。我沒有問題,使用C項目,但與C++我不斷收到錯誤:交叉g ++編譯器鏈接器錯誤

libc.a(lib_a-abort.o): In function `abort': 
abort.c:63: undefined reference to `_exit' 

libc.a(lib_a-sbrkr.o): In function `_sbrk_r': 
sbrkr.c:58 undefined reference to `_sbrk' 

libc.a(lib_a-signalr.o): In function `_kill_r': 
signalr.c:61: undefined reference to `_kill' 

還有:

undefined reference to `_getpid' 
undefined reference to `_write' 
undefined reference to `_close' 
undefined reference to `_fstat' 
undefined reference to `_isatty' 
undefined reference to `_lseek' 
undefined reference to `_read' 

環視它看起來像我有一個連接問題。我試圖添加鏈接器flash.ld。它來自Atmel Studio的ARM開發套件的GCC示例。這沒有幫助。某處有g ++的鏈接器嗎?我還有其他問題嗎?

這裏是我的編譯選項:

make all 
Building target: Foo 
Invoking: Cross G++ Linker 
arm-none-eabi-g++ -nostartfiles -T C:/Users/kempsa/eclipse_workspace/Foo/flash.ld -o"Foo" ./HALTimer1.o ./Main.o 

我源文件Main.cpp的,HALTimer1.cpp和頭文件Haltimer.h。主文件只包含頭文件。頭文件僅爲一個變量定義了HALTimer的類。我不相信這些會影響錯誤。我相信這個錯誤完全來自於搭建一個沒有正確鏈接器文件的g ++項目。

這裏是連接文件的內容:

/** 
* \file 
* 
* \brief Flash Linker script for SAM. 
* 
* Copyright (c) 2011-2012 Atmel Corporation. All rights reserved. 
* 


    OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") 
    OUTPUT_ARCH(arm) 
    SEARCH_DIR(.) 

    /* Memory Spaces Definitions */ 
    MEMORY 
    { 
     rom (rx) : ORIGIN = 0x00400000, LENGTH = 0x00040000 /* flash has two banks, one bank = 256K */ 
    ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00010000 /* sram, 64K */ 
    } 

    /* The stack size used by the application. NOTE: you need to adjust */ 
    __stack_size__ = DEFINED(__stack_size__) ? __stack_size__ : 0x2000; 

    /* Section Definitions */ 
    SECTIONS 
    { 
     .text : 
     { 
      . = ALIGN(4); 
      _sfixed = .; 
      KEEP(*(.vectors .vectors.*)) 
      *(.text .text.* .gnu.linkonce.t.*) 
     *(.glue_7t) *(.glue_7) 
     *(.rodata .rodata* .gnu.linkonce.r.*) 
     *(.ARM.extab* .gnu.linkonce.armextab.*) 

     /* Support C constructors, and C destructors in both user code 
      and the C library. This also provides support for C++ code. */ 
     . = ALIGN(4); 
     KEEP(*(.init)) 
     . = ALIGN(4); 
     __preinit_array_start = .; 
     KEEP (*(.preinit_array)) 
     __preinit_array_end = .; 

     . = ALIGN(4); 
     __init_array_start = .; 
     KEEP (*(SORT(.init_array.*))) 
     KEEP (*(.init_array)) 
     __init_array_end = .; 

     . = ALIGN(0x4); 
     KEEP (*crtbegin.o(.ctors)) 
     KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) 
     KEEP (*(SORT(.ctors.*))) 
     KEEP (*crtend.o(.ctors)) 

     . = ALIGN(4); 
     KEEP(*(.fini)) 

     . = ALIGN(4); 
     __fini_array_start = .; 
     KEEP (*(.fini_array)) 
     KEEP (*(SORT(.fini_array.*))) 
     __fini_array_end = .; 

     KEEP (*crtbegin.o(.dtors)) 
     KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) 
     KEEP (*(SORT(.dtors.*))) 
     KEEP (*crtend.o(.dtors)) 

     . = ALIGN(4); 
     _efixed = .;   /* End of text section */ 
    } > rom 

    /* .ARM.exidx is sorted, so has to go in its own output section. */ 
    PROVIDE_HIDDEN (__exidx_start = .); 
    .ARM.exidx : 
    { 
     *(.ARM.exidx* .gnu.linkonce.armexidx.*) 
    } > rom 
    PROVIDE_HIDDEN (__exidx_end = .); 

    . = ALIGN(4); 
    _etext = .; 

    .relocate : AT (_etext) 
    { 
     . = ALIGN(4); 
     _srelocate = .; 
     *(.ramfunc .ramfunc.*); 
     *(.data .data.*); 
     . = ALIGN(4); 
     _erelocate = .; 
    } > ram 

    /* .bss section which is used for uninitialized data */ 
    .bss (NOLOAD) : 
    { 
     . = ALIGN(4); 
     _sbss = . ; 
     _szero = .; 
     *(.bss .bss.*) 
     *(COMMON) 
     . = ALIGN(4); 
     _ebss = . ; 
     _ezero = .; 
    } > ram 

    /* stack section */ 
    .stack (NOLOAD): 
    { 
     . = ALIGN(8); 
      _sstack = .; 
     . = . + __stack_size__; 
     . = ALIGN(8); 
     _estack = .; 
    } > ram 

    . = ALIGN(4); 
    _end = . ; 
} 

完整的編譯器輸出:

Building target: Foo 
Invoking: Cross G++ Linker 
arm-none-eabi-g++ -nostartfiles -T C:/Users/kempsa/eclipse_workspace/Foo/flash.ld -o"Foo"  ./HALTimer.o ./Main.o 
c:/yagarto/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib\libc.a(lib_a-abort.o): In function `abort': 
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\stdlib/../../../../../newlib-1.20.0/newlib/libc/stdlib/abort.c:63: undefined reference to `_exit' 
c:/yagarto/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib\libc.a(lib_a-sbrkr.o): In function `_sbrk_r': 
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.20.0/newlib/libc/reent/sbrkr.c:58: undefined reference to `_sbrk' 
c:/yagarto/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib\libc.a(lib_a-signalr.o): In function `_kill_r': 
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.20.0/newlib/libc/reent/signalr.c:61: undefined reference to `_kill' 
c:/yagarto/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib\libc.a(lib_a-signalr.o): In function `_getpid_r': 
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.20.0/newlib/libc/reent/signalr.c:96: undefined reference to `_getpid' 
c:/yagarto/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib\libc.a(lib_a-writer.o): In function `_write_r': 
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.20.0/newlib/libc/reent/writer.c:58: undefined reference to `_write' 
c:/yagarto/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib\libc.a(lib_a-closer.o): In function `_close_r': 
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.20.0/newlib/libc/reent/closer.c:53: undefined reference to `_close' 
c:/yagarto/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib\libc.a(lib_a-fstatr.o): In function `_fstat_r': 
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.20.0/newlib/libc/reent/fstatr.c:62: undefined reference to `_fstat' 
c:/yagarto/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib\libc.a(lib_a-isattyr.o): In function `_isatty_r': 
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.20.0/newlib/libc/reent/isattyr.c:58: undefined reference to `_isatty' 
c:/yagarto/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib\libc.a(lib_a-lseekr.o): In function `_lseek_r': 
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.20.0/newlib/libc/reent/lseekr.c:58: undefined reference to `_lseek' 
c:/yagarto/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib\libc.a(lib_a-readr.o): In function `_read_r': 
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.20.0/newlib/libc/reent/readr.c:58: undefined reference to `_read' 
collect2.exe: error: ld returned 1 exit status 
make: *** [Foo] Error 1 
+0

好吧,如果你認爲這是一個鏈接器文件問題,那麼列出你的'C:/ Users/kempsa/eclipse_workspace/Foo/flash.ld'鏈接器命令文件的內容。 – phonetagger

+1

嘗試使用gcc和g ++的'-v'選項,查看差異。 –

+0

驗證您嘗試鏈接在一起的對象和庫是否通過使用'objdump -af * .o * .a'檢查它們的相同體系結構 –

回答

0

添加鏈接選項-Wl, - GC-部分和問題應該得到解決

+0

你不應該發表這個答案 - 而是將其包含在你的問題中。現在就爲你做。 – ChrisWue