我有一个 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/