包含 stdio makefile

发布于 2024-08-12 21:35:10 字数 658 浏览 7 评论 0原文

我正在尝试使用 sprintf() 函数。因此我必须将 stdio.h 包含在我的 C 项目中。如果我编译项目时未在 makefile 中包含 stdio.h,则编译器会生成错误:sprintf() 是未知函数。将 stdio.h 包含到 makefile 中会生成“没有生成目标的规则”的错误。

makefile 模板给出的选项如下:

NAME   = test

CC      = arm-none-eabi-gcc
LD      = arm-none-eabi-ld -v
AR      = arm-none-eabi-ar
AS      = arm-none-eabi-as
CP      = arm-none-eabi-objcopy
OD      = arm-none-eabi-objdump

CFLAGS  =  -I./ -c -fno-common -O0 -g -mcpu=cortex-m3 -mthumb 
AFLAGS  = -ahls -mapcs-32 -o crt.o
ASFLAGS = -Wa,-gstabs 
LFLAGS  = -Tlinkerscript_rom.cmd -nostartfiles
CPFLAGS = -Obinary
ODFLAGS = -S

我希望你能帮助我,因为我不想重写每个标准函数。

斯文

I'm trying to use the sprintf() function. Therefore I have to include the stdio.h in my C project. If I compile the project without including the stdio.h in my makefile, the compiler generates the error that sprintf() is a unknown function. Including the stdio.h to the makefile generates the error that there is "no rule to make target."

The makefile template gives the options as follows:

NAME   = test

CC      = arm-none-eabi-gcc
LD      = arm-none-eabi-ld -v
AR      = arm-none-eabi-ar
AS      = arm-none-eabi-as
CP      = arm-none-eabi-objcopy
OD      = arm-none-eabi-objdump

CFLAGS  =  -I./ -c -fno-common -O0 -g -mcpu=cortex-m3 -mthumb 
AFLAGS  = -ahls -mapcs-32 -o crt.o
ASFLAGS = -Wa,-gstabs 
LFLAGS  = -Tlinkerscript_rom.cmd -nostartfiles
CPFLAGS = -Obinary
ODFLAGS = -S

I hope that you can help me out, because I have no desire to rewrite every standard function.

Sven

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

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

发布评论

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

评论(3

玉环 2024-08-19 21:35:10

Makefile 不读取包含文件。 C 预处理器在编译器编译生成的文件之前读取包含文件。您应该将标头包含在 C 文件中。只需添加:

#include <stdio.h>

在靠近顶部的位置,在任何函数定义之前等。

这将向编译器显示函数的声明,这将删除警告。

Makefiles don't read include files. The C preprocessor reads include files, before the resulting file is compiled by the compiler. You should include the header in your C file. Just add:

#include <stdio.h>

Somewhere close to the top, before any function definitions etc.

This will show a declaration of the function to the compiler, which will remove the warning.

暖心男生 2024-08-19 21:35:10

只需在 c 文件的顶部包含 stdio.h 将

#include <stdio.h>

.h 文件放入 makefile 中的唯一原因是,如果标头中的任何内容发生更改,则依赖于标头的文件将被重新编译。不用说,这在您编写的头文件中最常见。

Just include stdio.h at the top of your c file

#include <stdio.h>

The only reason to put a .h file in your makefile is so that the files dependent upon your header will be recompiled if anything in the header is changed. Needless to say, this is most commonly with header files you have written.

南城旧梦 2024-08-19 21:35:10

如果包含 stdio.h 后出现错误,则说明工具链已损坏。如果您更新问题以表明您的平台,我们也许可以帮助您解决它:)

If there is an error after including stdio.h, you have a broken tool chain. If you update your question to indicate your platform, we may be able to help you fix it :)

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