linux - 为什么可执行文件不接收 Makefile 中导出的变量?

标签 linux makefile export

我有一个 makefile,我在其中导出将由可执行文件接收的变量,但令人惊讶的是可执行文件没有接收导出的值。

请帮帮我。

31 test:
32         @ echo
33         @ echo "Testing Electric Fence."
34         @ echo "After the last test, it should print that the test has PASSED."
35         ./eftest
36         ./tstheap 3072
37         export EF_ERRTRACK_START=3
38         export EF_ERRTRACK_END=5
39         ./time-interval-measurement-test
40         @ echo
41         @ echo "Electric Fence confidence test PASSED." 
42         @ echo

time-interval-measurement-test 是一个可执行文件(C 程序),它应该接收导出的变量,但它没有接收到。请帮助我。

最佳答案

如果我没记错的话,Makefile 中的每一行都是一个单独的 shell 进程。所以 shell-export 不适用于多个进程:一种方法是将它们放在一行中:

test:
         @ echo
         @ echo "Testing Electric Fence."
         @ echo "After the last test, it should print that the test has PASSED."
         ./eftest
         ./tstheap 3072
         EF_ERRTRACK_START=3 EF_ERRTRACK_END=5 ./time-interval-measurement-test
         @ echo
         @ echo "Electric Fence confidence test PASSED." 
         @ echo

或用'\'转义换行符

test:
        [..]
        EF_ERRTRACK_START=3 \
        EF_ERRTRACK_END=5 \
        ./time-interval-measurement-test

就像 ENV 变量可用于 ./time-interval-measrument

关于linux - 为什么可执行文件不接收 Makefile 中导出的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6995107/

相关文章:

c++ - 无法在 makefile 中链接 opengl 库

c++ - 为 C/C++ 中的项目的 makefile 生成依赖项

gcc - 使文件不起作用?

angular - export *(星号)在 Angular/Typescript 中是什么意思

hadoop - Sqoop导出错误-cause:org.apache.hadoop.mapreduce.lib.input.InvalidInputException:输入路径不存在

node.js - React 创建应用程序热重载并不总是在 linux 上工作

linux - bash 脚本将输出分配给变量失败

linux - 从 root 帐户执行 cron 作业是否安全?

android - 在哪里可以找到 .apk 文件?

c++ - 在 Slackware 14.2 64 位上使用 ACE lib 编译错误