2013-03-27 58 views
1
mipsisa64-octeon-elf-gcc obj/zxmd_main.o obj/zxmd_mproc.o obj/zxmd_init.o obj/zxmd_pcie.o obj/libcvm-common.a obj/libcvm-pci-drv.a obj/libcvmhfao.a obj/libocteon-hfa.a /home/jianxi/Juson/JusonFlow/sdk/OCTEON-SDK/components/hfa/lib-octeon/pp/octeon/se/libpp.a obj/libcvmx.a obj/libzxexe.a obj/libfdt.a -mfix-cn63xxp1 -march=octeon2 -o cn63hw1.bin 

GCC抱怨:GCC無法找到的.o存檔

obj/libzxexe.a(zxmx_tim.o): In function `zxmx_init_tim': 
/home/jianxi/Juson/JusonFlow/libexec/zxmx_tim.c:47: undefined reference to `cvmx_tim_setup' 

cvmx_tim_setup可以libcvmx.a發現:

[[email protected] obj]$ readelf -h libcvmx.a | grep "cvmx-tim.o" -A21 
File: libcvmx.a(cvmx-tim.o) 
ELF Header: 
    Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00 
    Class:        ELF32 
    Data:        2's complement, big endian 
    Version:       1 (current) 
    OS/ABI:       UNIX - System V 
    ABI Version:      0 
    Type:        REL (Relocatable file) 
    Machine:       MIPS R3000 
    Version:       0x1 
    Entry point address:    0x0 
    Start of program headers:   0 (bytes into file) 
    Start of section headers:   13424 (bytes into file) 
    Flags:        0x808d4001, noreorder, octeon2, eabi64, mips64r2 
    Size of this header:    52 (bytes) 
    Size of program headers:   0 (bytes) 
    Number of program headers:   0 
    Size of section headers:   40 (bytes) 
    Number of section headers:   33 
    Section header string table index: 30 

    [[email protected] obj]$ readelf -s cvmx-tim.o 
     27: 00000000 92 FUNC GLOBAL DEFAULT 1 cvmx_tim_start 
     28: 00000000 40 OBJECT GLOBAL DEFAULT 16 cvmx_tim 
     29: 00000060 56 FUNC GLOBAL DEFAULT 1 cvmx_tim_stop 
     30: 00000098 276 FUNC GLOBAL DEFAULT 1 cvmx_tim_shutdown 
     31: 000001b0 752 FUNC GLOBAL DEFAULT 1 cvmx_tim_setup 
     32: 00000000  0 NOTYPE GLOBAL DEFAULT UND cvmx_clock_get_rate 
     33: 00000000  0 NOTYPE GLOBAL DEFAULT UND cvmx_bootmem_alloc 
     34: 00000000  0 NOTYPE GLOBAL DEFAULT UND memset 
     35: 00000000  0 NOTYPE GLOBAL DEFAULT UND puts 
     36: 00000000  0 NOTYPE GLOBAL DEFAULT UND printf 

當我在命令添加cvmx-tim.o,GCC會成功執行:

mipsisa64-octeon-elf-gcc obj/cvmx-tim.o obj/zxmd_main.o obj/zxmd_mproc.o obj/zxmd_init.o obj/zxmd_pcie.o obj/libcvm-common.a obj/libcvm-pci-drv.a obj/libcvmhfao.a obj/libocteon-hfa.a /home/jianxi/Juson/JusonFlow/sdk/OCTEON-SDK/components/hfa/lib-octeon/pp/octeon/se/libpp.a obj/libcvmx.a obj/libzxexe.a obj/libfdt.a -mfix-cn63xxp1 -march=octeon2 -o cn63hw1.bin 

如果放在OBJ/zxmd_main.o前OBJ/libcvmx.a,GCC會報告更多的錯誤。

爲什麼GCC找不到在libcvmx.acvmx-tim.o

*.o順序將導致問題?

+0

1爲的問題的詳細說明 – JiuDong 2013-03-27 09:16:34

回答

0

這是庫的順序:由時間

obj/libcvmx.a obj/libzxexe.a 

鏈接搜索obj/libzxexe.a它已經處理obj/libcvmx.a - 它不會對沒有已經在當obj/libcvmx.a是拉什麼再次搜索它第一次進行處理。

更改這些庫的順序:

obj/libzxexe.a obj/libcvmx.a 
0

除了更改庫的順序,也可以強制cvmx_tim_setup是一個標記爲命令行「未定義」的象徵。如果符號是衆所周知的需要,那麼連接器將是在尋找它,記住它定義的第一個庫。 將此標誌添加到gcc命令:-Wl, - undefined = cvmx_tim_setup

此外,您還可以在gcc中嘗試使用--start-group和--end-group。 --start-group(要鏈接的二進制文件列表)--end-group。這將允許搜索完整的循環封閉。但會花費一些鏈接性能。

價: http://eli.thegreenplace.net/2013/07/09/library-order-in-static-linking

Paxym