Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC linaro compiler throws error "unknown type name size_t"

I am using GCC Linaro compiler for compiling my code. Its throwing the error unknown type name size_t from libio.h. Its included from stdio.h. In my code I am just including stdio.h.

Can any one please how to resolve this error.

like image 738
rashok Avatar asked Oct 16 '14 17:10

rashok


2 Answers

As per C99, §7.17, size_t is not a builtin type but defined in <stddef.h>.

Including the <stddef.h> header should fix your problem.

like image 148
DMP Avatar answered Oct 18 '22 04:10

DMP


For what it's worth, I had this exact same problem with a QT project, where I was using a Linaro compiler to (on both x86 Windows and x86 Linux) build for ARM Linux. Using the exact same code and .pro file, I had no problems building on Windows, but I had a litany of errors building on the Linux box, beginning with the unknown type name 'size_t' in libio.h which traced back to a #include <stdio.h>. I looked in the stdio.h (in the sysroot for the target hardware, not on the host machine), and a few lines down was #include <stddef.h> (much before #include <libio.h>), so stddef.h was definitely getting included. However, upon further inspection, stddef.h was completely empty with a file size of 1 byte. This was true for stddef.h in my sysroot and on my host machine. I have no idea why these files were empty.

Anyway, turns out I had an extraneous INCLUDEPATH += /usr/include/linux in my .pro file. On my Linux build machine, this added -I/usr/include/linux to the Makefile generated by qmake. On my Windows build machine, this added -isystem /usr/include/linux to the Makefile generated by qmake. Once I commented this out, these lines were removed from the Makefiles and it built right up on both build machines. -isystem /usr/include/linux apparently never caused any trouble on the Windows build machine, so there was no harm in removing INCLUDEPATH += /usr/include/linux.

I don't really know why this fixed my problem, but I suspect it was some kind of conflict between header files. Perhaps it was mixing host header files with sysroot header files, or creating a circular dependency somehow. GCC documentation says that anything included with the -I option will take precedence over a system header file. My best advice for this problem is to take a hard look at exactly which header files are being included and where they are coming from.

like image 45
yano Avatar answered Oct 18 '22 04:10

yano