当make执行遇到 Arguments too long

文章讲述了在Ubuntu20.04环境下使用make编译时遇到的命令参数过长错误,通过检查系统命令缓冲区大小、查阅官方文档和升级make版本来解决问题的过程。
摘要由CSDN通过智能技术生成

1. 问题

Ubuntu20.04上make编译生成so的时候报错:

make[1]:execvp:/bin/sh:Arguments too long

对应makefile中的报错位置,仅仅是生成so的时候报错,伪代码如下

${build_tool} -shared -fpic -o "$@" ${OBJ_FILE} ${LDFLAGS}

然而如果不通过make执行,将后面的参数打印出来后,直接用交叉编译链执行是可以的,所以怀疑方向是在make

2. 分析:
(1)查看系统命令缓冲区大小,通过命令

xargs --show-limits

执行结果:

limit

同时我也将这个库的合包段参数打出来看,确实很多 ,达到了 262 822(超过了系统 命令缓冲区的大小: 131072)

(2)进行一系列查询,到了ubuntu官方去查询,在make的changelog中又有找到类似问题的修复说明:


changelog

进一步在4.1的新版本4.1.9中的diff里找到有对应的修复4.1.9-diff,但4.2.1的版本里却没看到相关补丁内容,看起来是没有合到4.2.1中,那接下来尝试回退版本试试

3. 更新make版本实验验证

搭建虚拟机,匹配到Ubuntu 20.04,先用安装make V4.2.1版本进行编译复现问题,再降级到补丁的make版本进行编译观察是否解决
####(1)make V4.2.1版本安装: 装虚拟机后再 apt安装make即可
make-version
确认安装后Make版本一致,均为4.2.1,接下来进行make编译
arguments too long
编译结果现象一致

(2)补丁版本降级安装:

下载补丁版本:

https://mirrors.tscak.com/ubuntu/pool/main/m/make-dfsg/

下载对应的deb,我的安装包:

ubuntu-20.04.1-desktop-amd64.iso,uname -a

也看得到

root@ubuntu:~/make-4.1.9# uname -a Linux ubuntu 5.15.0-60-generic #66~20.04.1-Ubuntu SMP Wed Jan 25 09:41:30 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

所以下载:make_4.1-9.1ubuntu1_amd64.deb

下载到了直接编译好的deb,然后进行安装(中间遇到两次报错也记录了出来,也可以直接看最后一次正确安装)

root@ubuntu:~/make-4.1.9# sudo apt install make_4.1-9.1ubuntu1_amd64.deb  
Reading package lists... Done 
Building dependency tree        
Reading state information... Done 
E: Unable to locate package make_4.1-9.1ubuntu1_amd64.deb 

报错:

Unable to locate package make_4.1-9.1ubuntu1_amd64.deb

注意:(1)一定找对目录,到存在deb文件目录 (2)要安装的文件需要真的在这个文件夹下,然后以相对路径去执行,即加上 ./

root@ubuntu:~/make-4.1.9# sudo apt install -y ./make_4.1-9.1ubuntu1_amd64.deb
Reading package lists... Done 
Building dependency tree        
Reading state information... Done 
Note, selecting 'make' instead of './make_4.1-9.1ubuntu1_amd64.deb' 
Suggested packages:   
make-doc 
The following packages will be DOWNGRADED:   
make 
0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 238 not upgraded. 
E: Packages were downgraded and -y was used without --allow-downgrades.

报错:

Packages were downgraded and -y was used without --allow-downgrades.

正确安装:由于 包已经下在本地了,所以不需要-y, 去掉后重新装一次:

root@ubuntu:~/make-4.1.9# sudo apt install  ./make_4.1-9.1ubuntu1_amd64.deb    
Reading package lists... Done 
Building dependency tree        
Reading state information... Done 
Note, selecting 'make' instead of './make_4.1-9.1ubuntu1_amd64.deb' 
Suggested packages:   
make-doc 
The following packages will be DOWNGRADED:   
make 
0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 238 not upgraded. 
Need to get 0 B/154 kB of archives. 
After this operation, 12.3 kB disk space will be freed. 
Do you want to continue? [Y/n] y 
Get:1 /root/make-4.1.9/make_4.1-9.1ubuntu1_amd64.deb make amd64 4.1-9.1ubuntu1 [154 kB] 
dpkg: warning: downgrading make from 4.2.1-1.2 to 4.1-9.1ubuntu1 
(Reading database ... 238557 files and directories currently installed.) 
Preparing to unpack .../make_4.1-9.1ubuntu1_amd64.deb ... 
Unpacking make (4.1-9.1ubuntu1) over (4.2.1-1.2) ... 
Setting up make (4.1-9.1ubuntu1) ... Processing triggers for man-db (2.9.1-1) ... 
N: Download is performed unsandboxed as root as file '/root/make-4.1.9/make_4.1-9.1ubuntu1_amd64.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied) 
root@ubuntu:~/make-4.1.9# make --version  
GNU Make 4.1 
Built for x86_64-pc-linux-gnu 
Copyright (C) 1988-2014 Free Software Foundation, Inc. 
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 
This is free software: you are free to change and redistribute it. 
There is NO WARRANTY, to the extent permitted by law. 
root@ubuntu:~/make-4.1.9# 

这里就能看到,原本是 4.2.1-1.2 降级到了 4.1-9。接下来再进行make,就能通过了

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值