我试图在我的Mac(OSX版本10.14.1,Xcode版本10.1)上建立一个库,但它失败并给出以下错误:
Building target: application.a
ar -r "application.a" api.o
ar: creating archive application.a
/opt/local/bin/ranlib: object: application.a(api.o) malformed object (unknown load command 1)
ar: internal ranlib command failed
make[1]: *** [application.a] Error 1
make: *** [all] Error 2
通过运行'otool -l lib / api.o',我得到以下结果:
Mach header
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
0xfeedfacf 16777223 3 0x00 1 5 616 0x00002000
Load command 0
cmd LC_SEGMENT_64
cmdsize 472
segname
vmaddr 0x0000000000000000
vmsize 0x0000000000004fb0
fileoff 648
filesize 20400
maxprot 0x00000007
initprot 0x00000007
nsects 5
flags 0x0
Section
sectname __text
segname __TEXT
addr 0x0000000000000000
size 0x00000000000040ae
offset 648
align 2^4 (16)
reloff 21048
nreloc 329
flags 0x80000400
reserved1 0
reserved2 0
Section
sectname __cstring
segname __TEXT
addr 0x00000000000040ae
size 0x00000000000000cb
offset 17206
align 2^0 (1)
reloff 0
nreloc 0
flags 0x00000002
reserved1 0
reserved2 0
Section
sectname __const
segname __TEXT
addr 0x0000000000004180
size 0x000000000000003f
offset 17416
align 2^4 (16)
reloff 0
nreloc 0
flags 0x00000000
reserved1 0
reserved2 0
Section
sectname __compact_unwind
segname __LD
addr 0x00000000000041c0
size 0x00000000000005e0
offset 17480
align 2^3 (8)
reloff 23680
nreloc 47
flags 0x02000000
reserved1 0
reserved2 0
Section
sectname __eh_frame
segname __TEXT
addr 0x00000000000047a0
size 0x0000000000000810
offset 18984
align 2^3 (8)
reloff 0
nreloc 0
flags 0x6800000b
reserved1 0
reserved2 0
Load command 1
cmd ?(0x00000032)
cmdsize 24
Load command 2
cmd LC_DATA_IN_CODE
cmdsize 16
dataoff 24056
datasize 8
Load command 3
cmd LC_SYMTAB
cmdsize 24
symoff 24064
nsyms 93
stroff 25552
strsize 1668
Load command 4
cmd LC_DYSYMTAB
cmdsize 80
ilocalsym 0
nlocalsym 15
iextdefsym 15
nextdefsym 39
iundefsym 54
nundefsym 39
tocoff 0
ntoc 0
modtaboff 0
nmodtab 0
extrefsymoff 0
nextrefsyms 0
indirectsymoff 0
nindirectsyms 0
extreloff 0
nextrel 0
locreloff 0
nlocrel 0
我猜我的gcc和osx版本之间的load command miss匹配,但是在mach-o/loader.h上找不到0x00000032命令。有人对此有任何线索吗?
这是'otool --version':
llvm-otool(1): Apple Inc. version cctools-895
LLVM (http://llvm.org/):
LLVM version 4.0.1
Optimized build.
Default target: x86_64-apple-darwin18.2.0
Host CPU: haswell
Registered Targets:
aarch64 - AArch64 (little endian)
aarch64_be - AArch64 (big endian)
amdgcn - AMD GCN GPUs
arm - ARM
arm64 - ARM64 (little endian)
armeb - ARM (big endian)
bpf - BPF (host endian)
bpfeb - BPF (big endian)
bpfel - BPF (little endian)
hexagon - Hexagon
lanai - Lanai
mips - Mips
mips64 - Mips64 [experimental]
mips64el - Mips64el [experimental]
mipsel - Mipsel
msp430 - MSP430 [experimental]
nvptx - NVIDIA PTX 32-bit
nvptx64 - NVIDIA PTX 64-bit
ppc32 - PowerPC 32
ppc64 - PowerPC 64
ppc64le - PowerPC 64 LE
r600 - AMD GPUs HD2XXX-HD6XXX
riscv32 - 32-bit RISC-V
riscv64 - 64-bit RISC-V
sparc - Sparc
sparcel - Sparc LE
sparcv9 - Sparc V9
systemz - SystemZ
thumb - Thumb
thumbeb - Thumb (big endian)
x86 - 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64
xcore - XCore
答案 0 :(得分:0)
您是否安装了Macports?我遇到了同样的问题,macports cctool
软件包似乎安装了一个/opt/local/bin/otool
,这很可能在您的发展道路上遥遥领先。我怀疑/usr/bin/otool
给出了正确的答案...