gcc在档案中找不到.o

时间:2013-03-27 09:05:15

标签: gcc

 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抱怨:

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

[jianxi@jianxi 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

  [jianxi@jianxi 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 / libcvmx.a放在obj / zxmd_main.o前面,gcc将报告更多错误。

为什么gcc在cvmx-tim.o中找不到libcvmx.a

*.o的顺序会导致问题吗?

2 个答案:

答案 0 :(得分:0)

这是图书馆的顺序:

obj/libcvmx.a obj/libzxexe.a

当链接器搜索obj/libzxexe.a时,它已经处理了obj/libcvmx.a - 当第一次处理obj/libcvmx.a时,它不再搜索任何尚未被提取的内容时间到了。

将这些库的顺序更改为:

obj/libzxexe.a obj/libcvmx.a

答案 1 :(得分:0)

除了更改库的顺序之外,您还可以强制cvmx_tim_setup标记为' undefined'命令行中的符号。如果已知该符号是必需的,那么链接器将在它上面并且记住定义它的第一个库。 将此标志添加到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