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

时间:2011-08-09 10:58:21

标签: 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程序),它应该接收导出的变量,但它没有得到。请帮帮我。

2 个答案:

答案 0 :(得分:5)

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

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

答案 1 :(得分:2)

我曾要求提出类似的问题,但问题并非完全相同 how to implement makefile shared variable

理想情况下,您导出的变量应该传递给子进程,我想知道您的子shell是否与父进程相同。

试试以下 - export EF_ERRTRACK_START = 3; export EF_ERRTRACK_END = 5; ./time-interval-measurement-test