Alexander Samoylov
Alexander Samoylov

Reputation: 2558

"ar -r" allows creation of an empty library

The "ar" tool from Binutils does not fail if no input files are specified in the command line when it is used with -r parameter.

It can cause creation of an empty output file in such a common use-case as writing of a list of input object files and static libraries into a generated file if the generated file name is malformed or wrongly calculated by a script or a makefile.

ar -r output.a `cat myInputFile`
cat: myInputFile: No such file or directory
ar: creating output.a

So if cat fails its output gets empty and an empty output.a is generated. I find it weird that ar does not fail in this case. I am curious what can be the reason to allow ar making a zero-size static libraries?

ar -V
GNU ar (GNU Binutils for Ubuntu) 2.24

Upvotes: 0

Views: 1144

Answers (1)

Gregory Pakosz
Gregory Pakosz

Reputation: 70204

Works for me:

$ ar unknown.a 2>/dev/null || echo 'ko'
ko

$ ar -V
GNU ar (GNU Binutils) 2.28.0.20170506
Copyright (C) 2017 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.

Likely your version of ar is too old.

Upvotes: 0

Related Questions