C和程序集之间的链接错误

C和程序集之间的链接错误,c,gcc,assembly,linker,C,Gcc,Assembly,Linker,我正在编译一个c文件foo.c: #include <stdlib.h> extern void *memcpy_optimized(void* __restrict, void* __restrict, size_t); void foo() { [blah blah blah] memcpy_optimized((void *)a, (void *)b, 123); } 这两个文件都可以使用:gcc$ ,必须在汇编中使用代码< >代码>优化的。我之所以这

我正在编译一个c文件foo.c:

#include <stdlib.h>

extern void *memcpy_optimized(void* __restrict, void* __restrict, size_t);

void foo() {

    [blah blah blah]

    memcpy_optimized((void *)a, (void *)b, 123);
}
这两个文件都可以使用:gcc$<-o$@-c进行良好编译

但是,当我将应用程序与两个结果对象链接时,会出现以下错误:

foo.c:(.text+0x380): undefined reference to `memcpy_optimized(void*, void *, unsigned int)'
知道我做错了什么吗

readelf -a obj/memcpy_optimized.o 
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          436 (bytes into file)
  Flags:                             0x5000000, Version5 EABI
  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:         11
  Section header string table index: 8

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00000000 000040 0000f0 00  AX  0   0 16
  [ 2] .data             PROGBITS        00000000 000130 000000 00  WA  0   0  1
  [ 3] .bss              NOBITS          00000000 000130 000000 00  WA  0   0  1
  [ 4] .ARM.extab        PROGBITS        00000000 000130 000000 00   A  0   0  1
  [ 5] .ARM.exidx        ARM_EXIDX       00000000 000130 000008 00  AL  1   0  4
  [ 6] .rel.ARM.exidx    REL             00000000 00044c 000010 08      9   5  4
  [ 7] .ARM.attributes   ARM_ATTRIBUTES  00000000 000138 000023 00      0   0  1
  [ 8] .shstrtab         STRTAB          00000000 00015b 000056 00      0   0  1
  [ 9] .symtab           SYMTAB          00000000 00036c 0000b0 10     10   9  4
  [10] .strtab           STRTAB          00000000 00041c 00002f 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

There are no section groups in this file.

There are no program headers in this file.

Relocation section '.rel.ARM.exidx' at offset 0x44c contains 2 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0000012a R_ARM_PREL31      00000000   .text
00000000  00000a00 R_ARM_NONE        00000000   __aeabi_unwind_cpp_pr0

Unwind table index '.ARM.exidx' at offset 0x130 contains 1 entries:

0x0 <memcpy_optimized>: 0x80b0b0b0
  Compact model 0
  0xb0      finish
  0xb0      finish
  0xb0      finish


Symbol table '.symtab' contains 11 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 00000000     0 SECTION LOCAL  DEFAULT    1 
     2: 00000000     0 SECTION LOCAL  DEFAULT    2 
     3: 00000000     0 SECTION LOCAL  DEFAULT    3 
     4: 00000000     0 NOTYPE  LOCAL  DEFAULT    1 $a
     5: 00000000     0 SECTION LOCAL  DEFAULT    4 
     6: 00000000     0 SECTION LOCAL  DEFAULT    5 
     7: 00000000     0 NOTYPE  LOCAL  DEFAULT    5 $d
     8: 00000000     0 SECTION LOCAL  DEFAULT    7 
     9: 00000000     0 FUNC    GLOBAL DEFAULT    1 memcpy_optimized
    10: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __aeabi_unwind_cpp_pr0

No version information found in this file.
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "7-A"
  Tag_CPU_arch: v7
  Tag_CPU_arch_profile: Application
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-2
  Tag_FP_arch: VFPv3
  Tag_Advanced_SIMD_arch: NEONv1
  Tag_DIV_use: Not allowed
readelf-a obj/memcpy_optimized.o
ELF标头:
魔术:7f 45 4c 46 01 01 00 00
类别:ELF32
数据:2的补码,小尾端
版本:1(当前版本)
OS/ABI:UNIX-SystemV
ABI版本:0
类型:REL(可重定位文件)
机器:手臂
版本:0x1
入口点地址:0x0
程序头的开始:0(文件中的字节)
节头的开头:436(文件中的字节)
标志:0x5000000,版本5 EABI
此标头的大小:52(字节)
程序头的大小:0(字节)
程序头数:0
节标题的大小:40(字节)
节头数:11
节头字符串表索引:8
章节标题:
[Nr]名称类型地址尺寸ES Flg Lk Inf Al
[0]空0000000000000000000
[1].文本程序00000000 000040 0000F000 AX 0 16
[2]。数据程序00000000 000130 00000000 WA 0 1
[3].bss NOBITS 00000000 000130 00000000 WA 0 1
[4].ARM.extab程序位00000000 000130 00000000 A 0 1
[5].ARM.exidx ARM_exidx 00000000 000130 000008 00 AL 1 0 4
[6].rel.ARM.exidx rel 00000000 00044c 000010 08 9 5 4
[7].ARM.attributes ARM_attributes 00000000 000138 000023 00 0 1
[8].shstrtab STRTAB 00000000 00015b 000056 00 0 1
[9].symtab symtab 00000000 00036c 0000b0 10 10 9 4
[10] .strtab strtab 00000000 00041c 00002f 00 0 1
标志的关键点:
W(写入)、A(分配)、X(执行)、M(合并)、S(字符串)
I(信息)、L(链接顺序)、G(组)、T(TLS)、E(排除)、x(未知)
O(需要额外的操作系统处理)O(特定于操作系统),p(特定于处理器)
此文件中没有节组。
此文件中没有程序头。
偏移量0x44c处的重新定位节“.rel.ARM.exidx”包含2个条目:
偏移信息类型符号。值符号。名称
00000000 0000012 A R_ARM_PREL31 00000000。文本
00000000 00000 A00 R_臂_无00000000_aeabi_展开_cpp_pr0
在偏移量0x130处展开表索引“.ARM.exidx”包含1个条目:
0x0:0x80B0
紧凑型0
0xb0完成
0xb0完成
0xb0完成
符号表“.symtab”包含11个条目:
Num:值大小类型绑定到Ndx名称
0:00000000 0不键入本地默认值
1:00000000节本地默认值1
2:00000000节本地默认值2
3:00000000节本地默认值3
4:00000000不键入本地默认值1$a
5:00000000节本地默认值4
6:00000000节本地默认值5
7:00000000不键入本地默认值5$d
8:00000000节本地默认值7
9:00000000 FUNC全局默认值1内存优化
10:00000000不输入全局默认值和aeabi解卷cpp pr0
在此文件中找不到版本信息。
属性部分:aeabi
文件属性
标记CPU名称:“7-A”
标签:v7
Tag\u CPU\u arch\u配置文件:应用程序
Tag_ARM_ISA_用途:是
Tag_THUMB_ISA_用法:THUMB-2
标签FP拱门:VFPv3
Tag_Advanced_SIMD_arch:NEONv1
标记分区使用:不允许

在许多Unix和GCC C实现中,C中的名称在目标代码中以下划线开头。因此,在C++中调用<代码> MycPyPuxor优化> <代码>,必须在汇编中使用代码< >代码>优化的。我之所以这么说,是因为链接器报告了缺失函数的完整原型。C函数没有完整的原型作为其符号(只是函数的名称),但是C++的名称代表了函数的完整原型。

您的链接命令在哪里?GCC -O可执行文件FO。o@gregoiregentil你没有编译任何C++作为C + +?也许尝试写C,看看什么是由汇编程序生成的。您的过程使用C在i386上运行。为什么声明中说
extern void*
?这是我的问题。
readelf -a obj/memcpy_optimized.o 
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          436 (bytes into file)
  Flags:                             0x5000000, Version5 EABI
  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:         11
  Section header string table index: 8

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00000000 000040 0000f0 00  AX  0   0 16
  [ 2] .data             PROGBITS        00000000 000130 000000 00  WA  0   0  1
  [ 3] .bss              NOBITS          00000000 000130 000000 00  WA  0   0  1
  [ 4] .ARM.extab        PROGBITS        00000000 000130 000000 00   A  0   0  1
  [ 5] .ARM.exidx        ARM_EXIDX       00000000 000130 000008 00  AL  1   0  4
  [ 6] .rel.ARM.exidx    REL             00000000 00044c 000010 08      9   5  4
  [ 7] .ARM.attributes   ARM_ATTRIBUTES  00000000 000138 000023 00      0   0  1
  [ 8] .shstrtab         STRTAB          00000000 00015b 000056 00      0   0  1
  [ 9] .symtab           SYMTAB          00000000 00036c 0000b0 10     10   9  4
  [10] .strtab           STRTAB          00000000 00041c 00002f 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

There are no section groups in this file.

There are no program headers in this file.

Relocation section '.rel.ARM.exidx' at offset 0x44c contains 2 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0000012a R_ARM_PREL31      00000000   .text
00000000  00000a00 R_ARM_NONE        00000000   __aeabi_unwind_cpp_pr0

Unwind table index '.ARM.exidx' at offset 0x130 contains 1 entries:

0x0 <memcpy_optimized>: 0x80b0b0b0
  Compact model 0
  0xb0      finish
  0xb0      finish
  0xb0      finish


Symbol table '.symtab' contains 11 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 00000000     0 SECTION LOCAL  DEFAULT    1 
     2: 00000000     0 SECTION LOCAL  DEFAULT    2 
     3: 00000000     0 SECTION LOCAL  DEFAULT    3 
     4: 00000000     0 NOTYPE  LOCAL  DEFAULT    1 $a
     5: 00000000     0 SECTION LOCAL  DEFAULT    4 
     6: 00000000     0 SECTION LOCAL  DEFAULT    5 
     7: 00000000     0 NOTYPE  LOCAL  DEFAULT    5 $d
     8: 00000000     0 SECTION LOCAL  DEFAULT    7 
     9: 00000000     0 FUNC    GLOBAL DEFAULT    1 memcpy_optimized
    10: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __aeabi_unwind_cpp_pr0

No version information found in this file.
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "7-A"
  Tag_CPU_arch: v7
  Tag_CPU_arch_profile: Application
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-2
  Tag_FP_arch: VFPv3
  Tag_Advanced_SIMD_arch: NEONv1
  Tag_DIV_use: Not allowed