C语言 GCC linaro 编译器抛出错误“未知类型名称 size_t”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26410466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GCC linaro compiler throws error "unknown type name size_t"
提问by rashok
I am using GCC Linarocompiler for compiling my code. Its throwing the error unknown type name size_tfrom libio.h. Its included from stdio.h. In my code I am just including stdio.h.
我正在使用GCC Linaro编译器来编译我的代码。它unknown type name size_t从libio.h. 它包括从stdio.h. 在我的代码中,我只包括stdio.h.
Can any one please how to resolve this error.
任何人都可以请如何解决此错误。
回答by Andrew Piroli
As per C99, §7.17, size_tis not a builtin type but defined in <stddef.h>.
根据 C99,第 7.17 节,size_t不是内置类型,而是在<stddef.h>.
Including the <stddef.h>header should fix your problem.
包含<stddef.h>标题应该可以解决您的问题。
回答by yano
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.hwhich 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.hwas definitely getting included. However, upon further inspection, stddef.hwas completely empty with a file size of 1 byte. This was true for stddef.hin my sysroot and on my host machine. I have no idea why these files were empty.
值得一提的是,我在 QT 项目中遇到了完全相同的问题,我使用 Linaro 编译器(在 x86 Windows 和 x86 Linux 上)为 ARM Linux 构建。使用完全相同的代码和.pro文件,我没有问题,建立在Windows,但我有错误,构建在Linux中一连串的,与开始unknown type name 'size_t'在libio.h其中追溯到#include <stdio.h>。我查看了stdio.h(在目标硬件的 sysroot 中,而不是在主机上),下面几行是#include <stddef.h>(很早以前#include <libio.h>),所以stddef.h肯定被包括在内。但是,经过进一步检查,stddef.h文件大小为 1 个字节,完全为空。stddef.h在我的 sysroot 和我的主机上都是如此。我不知道为什么这些文件是空的。
Anyway, turns out I had an extraneous INCLUDEPATH += /usr/include/linuxin my .pro file. On my Linux build machine, this added -I/usr/include/linuxto the Makefile generated by qmake. On my Windows build machine, this added -isystem /usr/include/linuxto 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/linuxapparently never caused any trouble on the Windows build machine, so there was no harm in removing INCLUDEPATH += /usr/include/linux.
无论如何,事实证明我的INCLUDEPATH += /usr/include/linux.pro 文件中有一个无关紧要的文件。在我的 Linux 构建机器上,这将添加-I/usr/include/linux到 qmake 生成的 Makefile 中。在我的 Windows 构建机器上,这已添加-isystem /usr/include/linux到 qmake 生成的 Makefile 中。一旦我将其注释掉,这些行就从 Makefile 中删除了,并且它在两台构建机器上都建立起来了。 -isystem /usr/include/linux显然从未在 Windows 构建机器上造成任何问题,因此删除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 -Ioption 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.
我真的不知道为什么这解决了我的问题,但我怀疑这是头文件之间的某种冲突。也许是将主机头文件与 sysroot 头文件混合在一起,或者以某种方式创建了循环依赖。GCC 文档说该-I选项中包含的任何内容都将优先于系统头文件。对于这个问题,我最好的建议是仔细查看包含哪些头文件以及它们来自哪里。
回答by Galaxy
Both stdio.hand stdlib.hinclude the data type size_t. They include this data type because the functions declared in these headers either take size_tas a parameter, or return it as a return type. size_titself is a typedefto an unsigned integral type and it's also returned by the sizeofoperator.
两者stdio.h并stdlib.h包括该数据类型size_t。它们包含此数据类型,因为在这些标头中声明的函数要么将其size_t作为参数,要么将其作为返回类型返回。size_t本身是一个typedef无符号整数类型,它也由sizeof运算符返回。
And because the sizeofoperator is built into the C Programming Language itself, not included via some library, then how can size_tbe an unknown type name?
并且因为sizeof操作符是内置在 C 编程语言本身中的,没有包含在某个库中,那么怎么会size_t是一个未知的类型名称呢?

