c++ - 制作 : variable fails to assign from shell call

标签 c++ makefile gnu-make

# makefile

SHELL:=/bin/bash
PATH:=/path/to/new/programs:$(PATH)


my_var:=$(shell which program)

rule:
    echo $(my_var)
    which program

#output
$: make rule

echo 

which program
/path/to/program

# prints nothing

我已经尝试了所有方法,实际上还记得在我之前创建 makefile 时如何让它工作。它正在变成一个泥潭——我需要做的就是在安装它之前检查它是否存在。

最佳答案

如果您不在 makefile 中设置 SHELL 变量,显式 which 是否有效?

设置SHELL 变量只会影响配方。它不用于 $(shell ...) 函数。您可以使用:

my_var := $(shell /bin/bash -c 'which function')

但是在我的系统上,即使使用默认 shell 也可以使用 which。也许您的系统有所不同。

当然要注意哪个找到程序,而不是函数...

关于c++ - 制作 : variable fails to assign from shell call,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50727687/

相关文章:

cmake - Cmake、gnu make 和手动编译的区别

bash - Makefile:如何运行bash脚本并忽略其退出状态?

gcc - 如何将参数传递给 makefile 配方,或在解析时解析变量

c++ - 适合构图的智能指针

c++ - SWIG 和 CMake : make use of information provided by `target_include_directories()`

eclipse - 如何在 C++ Eclipse 项目中定义自定义构建命令而不是 "make all"?

makefile - 如何让CMake知道库位于某个目录中?

build - 如何构建freebsd内核?

c++ - 对基类成员数据的派生模板类访问

c# - 有没有办法从 C++ 程序编译和执行 C# 代码?