gpt4 book ai didi

bash - 使用 shell 变量传递选项时,autotools 配置错误

转载 作者:行者123 更新时间:2023-12-04 14:21:11 27 4
gpt4 key购买 nike

我希望从这样的 bash 脚本调用配置命令(编译 nginx):

CONF_OPTS=' --with-cc-opt="-O2 -g"'
./configure ${CONF_OPTS}

但我收到以下错误:
./configure: error: invalid option "-g"

当我通过以下选项时:
./configure --with-cc-opt="-O2 -g"

我没有错误。

重现:
curl -O  http://nginx.org/download/nginx-1.14.2.tar.gz
tar xfz nginx-1.14.2.tar.gz
cd nginx-1.14.2

OPTS='--with-cc-opt="-O2 -g"'
./configure ${OPTS}

结果
./configure: error: invalid option "-g""

但:
./configure --with-cc-opt="-O2 -g"

没关系

我认为这与 nginx 无关,但我认为这是 bash 引用替换问题。

最佳答案

它会像这样工作:

$ CC_OPTS=--with-cc-opt='-O2 -g'
$ ./configure "$CC_OPTS"

使 $CC_OPTS的扩展作为单个参数传递给 ./configure .

但如果你也想通过,也许:
--with-ld-opt='-Wl,-gc-sections -Wl,-Map=mapfile'

通过变量,您需要:
$ CC_OPTS=--with-cc-opt='-O2 -g'
$ LD_OPTS=--with-ld-opt='-Wl,-gc-sections -Wl,-Map=mapfile'
$ ./configure "$CC_OPTS" "$LD_OPTS"

因为您需要将两个参数传递给 ./configure , 和:
./configure "$CC_OPTS $LD_OPTS"

只通过一个,就会失败。

关于bash - 使用 shell 变量传递选项时,autotools 配置错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54750830/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com