Home > Enterprise >  "unknown type name 'size_t'" error from included .cpp file, but removed when inc
"unknown type name 'size_t'" error from included .cpp file, but removed when inc

Time:11-13

It's like the question title.
I was updating my program for arm64 machine. A file that was included was changed from "args.cpp" to "args.h". Inside the include file type size_t was being used(previously too). Now the compiler (aarch64-none-linux-gnu- ) complains with "unknown type name 'size_t'" error. If I change the included file name just to args.cpp, the errors are gone. Why is thing happening? and How can I use args.h as the included file name?

CodePudding user response:

#include <stddef.h> for size_t (C)

#include <cstddef> for std::size_t (C )

cstddef also defines size_t in the global namespace, although it is not guaranteed by the C standard.

CodePudding user response:

The problem was not in the code. In my Makefile, I mistakenly put $^ instead of $< as below.

%: %.c include/*.h
    $(CROSS_COMPILE)gcc -g -fmax-errors=5 -DQEMU -I$(AXPUDIR) -I$(INCDIR) $^ -o $@

So the make tried to compile the header file (which I put as prerequisite, to make it recompiled when I change the header file) which errors out because by itself the header file didn't have definition fo size_t. So I changed $^ to $< and the problem is gone. I feel sorry for misleading..

  • Related