tags:

views:

179

answers:

3

Im trying to use the sprintf() function. Therefore I has 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

+1  A: 

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.

unwind
A: 

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.

rzrgenesys187
A: 

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 :)

Tim Post
Ok, I added the platform. But I have no idea how to fix it.
Sven