在链接步骤期间在 Makefile 中使用 SDCC 时出现问题

发布于 2024-09-11 04:31:40 字数 881 浏览 2 评论 0原文

即使在链接步骤期间存在未定义的引用错误,小型设备 C 编译器 (SDCC) 也会生成 ihx (Intel Hex) 文件。在 Makefile 中使用 SDCC 时,此行为会导致问题,因为如果将 ihx 文件设置为 make 目标,则 make 无法知道先前的链接尝试是否失败。

当链接期间存在未定义的引用时,有没有办法告诉 SDCC 抑制 ihx 输出?如果没有,最好的解决方法是什么?(我已经想到了一个)。

另外,我对 SDCC 为何如此设计感兴趣(如果有人知道的话)。

这是问题的一个示例:

您有一个名为 test.c 的文件,它调用未定义的函数:

void foo();
void main()
{
    foo();
}

您有一个简单的 Makefile,用于从 test.c 构建 test.ihx:

test.ihx: test.c
    sdcc test.c

您尝试编译 test。第一次编译失败:

C:\test>make
sdcc test.c

?ASlink-Warning-Undefined Global '_foo' referenced by module 'test'
make: *** [test.ihx] Error 1

您尝试通过更改不依赖于 ihx 的内容(例如 Makefile)来解决问题,然后尝试再次编译:

C:\test>make
make: `test.ihx' is up to date.

但是 make 不会尝试编译它,因为 SDCC已经创建了 ihx 文件。

The Small Device C Compiler (SDCC) will produce a ihx (Intel Hex) file even if there are undefined reference errors during the link step. This behavior causes problems when using SDCC in a Makefile because if you set the ihx file to be your make target, then make has no good way of knowing that a previous attempt at linking has failed.

Is there a way to tell SDCC to suppress the ihx output when there is an undefined reference during linking? If not, what is the best workaround? (I already thought of one).

Also, I'm interested in why SDCC was designed this way if anyone knows.

Here's an example of the problem:

You have a file called test.c which calls an undefined function:

void foo();
void main()
{
    foo();
}

You have a simple Makefile for building a test.ihx from test.c:

test.ihx: test.c
    sdcc test.c

You try to compile test.c for the first time and it fails:

C:\test>make
sdcc test.c

?ASlink-Warning-Undefined Global '_foo' referenced by module 'test'
make: *** [test.ihx] Error 1

You try to fix the problem by changing something that is not a dependency of the ihx (such as the Makefile), and try to compile again:

C:\test>make
make: `test.ihx' is up to date.

But make doesn't try to compile it because SDCC already created the ihx file.

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

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

发布评论

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

评论(1

君勿笑 2024-09-18 04:31:40

我对sdcc一无所知,所以很抱歉我无法回答你关于是否可以抑制输出或者为什么sdcc是这样设计的问题。

我可以想到一个解决方法:成功构建后重命名 ihx 文件,并使用新名称作为 make 目标。

I don't know anything about sdcc, so I'm sorry that I can't answer your questions regarding whether the output can be suppressed or why sdcc was designed that way.

I can think of a work-around: Rename the ihx file after a successful build, and use the new name as the make target.

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