包含 stdio makefile
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Makefile 不读取包含文件。 C 预处理器在编译器编译生成的文件之前读取包含文件。您应该将标头包含在 C 文件中。只需添加:
在靠近顶部的位置,在任何函数定义之前等。
这将向编译器显示函数的声明,这将删除警告。
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:
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.
只需在 c 文件的顶部包含 stdio.h 将
.h 文件放入 makefile 中的唯一原因是,如果标头中的任何内容发生更改,则依赖于标头的文件将被重新编译。不用说,这在您编写的头文件中最常见。
Just include stdio.h at the top of your c file
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.
如果包含 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 :)