为什么在Makefile中导出的variables没有被可执行文件接收到?

我有一个生成文件,在那里我出口的variables将由可执行文件接收,但令人惊讶的是可执行文件没有收到导出的值。

请帮帮我。

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

如果我没有弄错,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

我曾经问过一个类似的问题,但是它不是完全相同的场景, 如何实现makefile共享变量

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

尝试以下 – 导出EF_ERRTRACK_START = 3; 导出EF_ERRTRACK_END = 5; ./time-interval-measurement-test