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

发布于 2024-11-29 01:09:10 字数 603 浏览 1 评论 0原文

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

I have a makefile, where i am exporting variables which will be received by an executable, but surprisingly the executable is not receiving the exported values.

Please help me.

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 is an executable (C program) which should receive the exported variables, but it is not getting. Please help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感受沵的脚步 2024-12-06 01:09:10

如果我没有记错的话,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

If I'm not mistaken each line in a Makefile is a separate shell-process. So shell-export does not work for several processes: One way to do it is to put them into one line:

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

or line-break-escaped with '\'

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

Like that the ENV-variables are available to ./time-interval-measrument

猫烠⑼条掵仅有一顆心 2024-12-06 01:09:10

我问过类似的问题,但情况不完全相同
如何实现 makefile 共享变量

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

尝试以下操作 -
导出 EF_ERRTRACK_START=3;导出 EF_ERRTRACK_END=5; ./时间间隔测量测试

I had asked for a similar question, but its not the exact same scenario
how to implement makefile shared variable

Ideally your exported variables should have passed on to the child process, I wonder if your child shell is same as parent.

Try following -
export EF_ERRTRACK_START=3; export EF_ERRTRACK_END=5; ./time-interval-measurement-test

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文