I've a SDK with some examples, but when I want to compile any of these examples, I receive this error:
cc -g -I -o this_example.o -c this_example.c
cc: error: this_example.o: No such file or directory
make: *** [Makefile:15: this_example.o] Error 1
Here is the makefile:
CC ?= gcc
INC_PATH ?= $(realpath ../inc)
LIB_PATH ?= $(realpath ../lib)
LIBS ?= $(wildcard $(LIB_PATH)/*.a) -pthread -lrt -lm
LDFLAGS :=-g -L$(LIB_PATH)
CFLAGS =-g -I$(INC_PATH)
EXAMPLES=sdk_this_example_folder
.PHONY: all
all: $(EXAMPLES)
%.o: %.c
$(CC) $(CFLAGS) -o $@ -c $<
this_example: this_example.o frozen.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) -Wl,-rpath,'$$ORIGIN/../../lib'
clean:
rm -f *~ *.o $(EXAMPLES)
In this_example_folder, I've four files: Makefile, this_example.c and frozen.c and frozen.h. Where is the problem? Thank you everybody for your help!
CodePudding user response:
The realpath
function returns the empty string if the path you are expanding doesn't exist.
You have:
INC_PATH ?= $(realpath ../inc)
then:
CFLAGS =-g -I$(INC_PATH)
and your command output is:
cc -g -I -o this_example.o -c this_example.c
Clearly, the value of INC_PATH
is empty (since there's nothing after the -I
in the command line) which means the directory ../inc
does not exist.
As for why you get that failure: the -I
option expects a filename afterwards. Since you don't have one, it uses -o
(the next word in the command line) as the filename. That means that this_example.o
is treated as a file to compile, rather than the output file, and of course it doesn't exist.