ar cannot create archive: "File format not recognized"
Asked Answered
D

2

9

I have this makefile

libjackpot.a: jackport.o jackpot.o
    ar -rcs jackport.o jackpot.o

jackpot.o: jackpot.cpp jackpot.h
    g++ jackpot.cpp -std=c++11 -O2 -c

jackport.o: jackport.cpp jackpot.h jackport.h
    g++ jackport.cpp -std=c++11 -O2 -c

Somehow (on my Linux box), I get

ar: jackport.o: File format not recognized

ar --help gives

ar: supported targets: elf64-x86-64 elf32-i386 elf32-x86-64 a.out-i386-linux pei-i386 pei-x86-64 elf64-l1om elf64-k1om elf64-little elf64-big elf32-little elf32-big plugin srec symbolsrec verilog tekhex binary ihex

file jackport.o

jackport.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
Daimon answered 27/7, 2013 at 19:20 Comment(0)
L
13

You need to specify the library name for ar, e.g.:

   ar -rcs libjackpot.a jackport.o jackpot.o
Lithoid answered 12/9, 2013 at 14:40 Comment(1)
How could I miss thatDaimon
B
1

Yes, archive name is missing. You also have access to the target name. In your case "libjackpot.a" with a variable "$@".

libjackpot.a: jackport.o jackpot.o
    ar -rcs $@ jackport.o jackpot.o

One step further, "$^" is the prerequisite list

libjackpot.a: jackport.o jackpot.o
    ar -rcs $@ $^
Bloodsucker answered 14/3 at 17:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.