致命错误:stdio.h:没有这样的文件或目录

时间:2018-12-29 23:40:59

标签: c compiler-errors

我在Mac Mojave 10.14.1上的#include <stdio.h>有问题

我有一个默认的gcc编译器以及其他gcc编译器。

DorothyeMacBook:Desktop dorothy$ which gcc
/usr/local/bin/gcc

版本是

DorothyeMacBook:Desktop dorothy$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin15.6.0/7.1.0/lto-wrapper
Target: x86_64-apple-darwin15.6.0
Configured with: ../gcc-7.1.0/configure --enable-languages=c++,fortran
Thread model: posix
gcc version 7.1.0 (GCC) 

现在,我正走在路上: / Users / dorothy / Desktop

我在库中有stdio.h

DorothyeMacBook:Desktop dorothy$ find /usr -name "stdio.h"
find: /usr/sbin/authserver: Permission denied
/usr/local/include/c++/7.1.0/tr1/stdio.h
/usr/local/include/c++/4.9.2/tr1/stdio.h
/usr/local/lib/gcc/x86_64-apple-darwin15.6.0/7.1.0/include/ssp/stdio.h
/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/include/ssp/stdio.h
/usr/local/Cellar/gcc/8.2.0/include/c++/8.2.0/tr1/stdio.h
/usr/local/Cellar/gcc/8.2.0/lib/gcc/8/gcc/x86_64-apple-darwin18.2.0/8.2.0/include/ssp/stdio.h
/usr/local/Cellar/gcc/8.2.0/lib/gcc/8/gcc/x86_64-apple-darwin18.2.0/8.2.0/include-fixed/stdio.h

但是,当我在当前路径下编译文件时,/ Users / dorothy / Desktop Terminal会给我一个错误:

DorothyeMacBook:Desktop dorothy$ gcc  inverse.c -o inv
inverse.c:1:10: fatal error: stdio.h: No such file or directory
 #include <stdio.h>
          ^~~~~~~~~
compilation terminated.

2 个答案:

答案 0 :(得分:1)

@Jonathan Leffler是正确的。苹果为我们做了另一个大蛋糕。 由于/ usr / include已被移动(安装命令行工具后现在位于/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include中),因此旧版本的gcc build 找不到最底层的包括文件。而是个问题。 (他们的头脑中有什么)所以只有您是使用/ usr / include的开发人员?

不是类似于Unix。

这是发生了什么事。对于gcc-4.9(以下gcc-4.9和gcc-9均为brew gcc。),包含搜索路径为:

enter ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
.
/usr/local/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
/usr/local/Cellar/gcc@4.9/4.9.4_1/lib/gcc/4.9/gcc/x86_64-apple-darwin17.3.0/4.9.4/include
/usr/local/Cellar/gcc@4.9/4.9.4_1/include
/usr/local/Cellar/gcc@4.9/4.9.4_1/lib/gcc/4.9/gcc/x86_64-apple-darwin17.3.0/4.9.4/include-fixed
/System/Library/Frameworks
/Library/Frameworks
End of search list. here

有系统级文件stdio.h,这就是为什么找不到stdio.h的原因。

问题所在:

inverse.c:1:10: fatal error: stdio.h: No such file or directory
#include <stdio.h>
      ^~~~~~~~~
compilation terminated.

请参阅/usr/local/Cellar/gcc@4.9/4.9.4_1/lib/gcc/4.9/gcc/x86_64-apple-darwin17.3.0/4.9.4/include/ssp/stdio.h

#ifndef _SSP_STDIO_H
#define _SSP_STDIO_H 1

#include <ssp.h>
#include_next <stdio.h>

#include_next意味着包含下一个名称stdio.h,该名称只是一个向导。

放弃使用。 cp /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include中的所有文件到/usr/local/Cellar/gcc@4.9/4.9.4_1/lib/gcc/4.9/gcc/x86_64-apple-darwin17。 3.0 / 4.9.4 / include-fixed,gcc-4.9将再次起作用。

但是对于gcc-9,路径问题很好。参见:

#include "..." search starts here:
#include <...> search starts here:
.
/usr/local/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include # key path
/usr/local/Cellar/gcc/9.1.0/lib/gcc/9/gcc/x86_64-apple-darwin18/9.1.0/include
/usr/local/Cellar/gcc/9.1.0/lib/gcc/9/gcc/x86_64-apple-darwin18/9.1.0/include-fixed
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks
End of search list.

实际上,只需重新安装xcode命令行工具即可解决此错误,之后gcc-4.9将再次起作用。

答案 1 :(得分:0)

在Mac上将gcc与stdio.h链接时,我仍然遇到问题。但是,我找到了另一种用gcc编译程序的方法。我在终端中输入brew install gcc,这意味着将安装新的gcc8.0.2。(这是我的情况,我不知道您会得到什么gcc)然后我使用gcc-8而不是gcc进行编译我的程序。这样,将调用新的gcc8.0.2。

您可以通过转至/ usr / local / bin来查看gcc变体的命令名称,其中列出了所有gcc命令的名称。对我来说 g ++
g ++-8
gcc
gcc-8

如果您还有其他问题,可以与我联系,我会提供更多详细信息。

相关问题