Linux 如何将x filename.a添加到其他目录

Linux 如何将x filename.a添加到其他目录,linux,unix-ar,Linux,Unix Ar,是否有将对象提取到其他目录的ar选项? 有没有办法将它们提取到下面的tmp [test]# ls -l total 1828 -rw-r--r-- 1 root root 1859628 Aug 24 02:10 libclsr11.a drwxr-xr-x 2 root root 4096 Aug 24 02:12 tmp [test]# ar x libclsr11.a [test]# ls -l total 3760 -rw-r--r-- 1 root root 157304 Au

是否有将对象提取到其他目录的ar选项? 有没有办法将它们提取到下面的tmp

[test]# ls -l
total 1828
-rw-r--r-- 1 root root 1859628 Aug 24 02:10 libclsr11.a
drwxr-xr-x 2 root root    4096 Aug 24 02:12 tmp
[test]# ar x libclsr11.a
[test]# ls -l
total 3760
-rw-r--r-- 1 root root  157304 Aug 24 02:13 clsrcact.o
-rw-r--r-- 1 root root   19304 Aug 24 02:13 clsrcclu.o
-rw-r--r-- 1 root root   55696 Aug 24 02:13 clsrccss.o
..
drwxr-xr-x 2 root root    4096 Aug 24 02:12 tmp
[test]#

不幸的是,ar似乎没有提供一种方法来指定提取文件的目录。(至少我找不到一个。)它总是使用当前目录。但是,有一个简单的解决方法:在提取之前更改到目标目录,并改为使用存档的相对路径:

# cd ./tmp/
# ar x ../libclsr11.a

这样,您就可以在./tmp/目录中找到clsract.o、clsrcclu.o和clsrccss.o。

实际上这是可能的,可能是最近更改的,
--output
选项是您需要的

在您的示例中:

ar x libclsr11.a --output tmp