clang 不编译 c 程序?

标签 c clang header-files llvm-clang

在用 c 编程时,我大部分时间都使用 clang 进行编译。突然它停止工作了。每当我尝试编译某些东西时,它都会给我这个输出 假设文件名为test.c

clang test.c 

In file included from test.c:1:
/usr/include/stdio.h:33:11: fatal error: 'stddef.h' file not found
# include <stddef.h>
          ^
1 error generated.

test.c 的来源是:

#include <stdio.h>
#include <stdlib.h>

int main( int argc, char *argv[] )
{
  printf("\nthis is a sample c program\n");
  return EXIT_SUCCESS;
}

注意:在 gcc 等其他编译器上它仍然有效。 我应该怎么做才能让 clang 恢复正常?

如果您需要有关系统的任何信息: 我正在使用 Ubuntu 13.10 32 位。 文本编辑器:Emacs。

我也试过卸载 clang 然后重新安装仍然得到同样的错误。


我在“usr/include/linux”中找到该文件,然后将其粘贴到“usr/include”中,它现在显示同一文件的错误但要求另一个文件

In file included from test.c:1:
In file included from /usr/include/stdio.h:74:
/usr/include/libio.h:50:10: fatal error: 'stdarg.h' file not found
#include <stdarg.h>
     ^
1 error generated.

现在我尝试搜索新文件“”,并在不同的文件夹中找到超过 1 个具有相同名称的文件,这让我感到困惑,我需要复制粘贴到 clang 想要的目录中。

有没有其他方法可以解决头文件的问题?


现在我找到了 clang 的 config.h 文件。负责包含文件的两个变量及其当前值在文件中如下:

/* Relative directory for resource files */
#define CLANG_RESOURCE_DIR ""

/* Directories clang will search for headers */
#define C_INCLUDE_DIRS "/usr/include/i386-linux-gnu:/usr/include/i686-linux-gnu:/usr/include"

但我不知道应该替换什么值才能使其正常工作。 这些是我可以完全重新配置 clang 的任何方式吗?

最佳答案

花了一些时间后,我发现由于“/usr/include/”目录中缺少头文件,clang 无法正常工作。 许多其他 Linux 用户也面临同样的问题。就我而言,这是由于更新到 Ubuntu 的新版本而发生的。

我通过以下方式删除了 clang:

sudo apt-get remove clang

然后安装了不同版本的clang-3.3

sudo apt-get install clang-3.3

现在 clang 对我来说工作正常。

关于clang 不编译 c 程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19969399/

相关文章:

cmake - 一起构建 clang 和 libc++ 的正确方法( Bootstrap )

ios - 更新到 Xcode 10.2、Swift 5 后 `' NBPhoneNumberDesc.h ' file not found`

c - 在 C 中使用类型#define 值进行除法

c - pow 函数的奇怪行为

c - 如何将与 OpenGL 一起使用的纹理嵌入到 C 数组中?

c - 如何为输入 la shell 的 `bg` 命令创建后台进程 block ?

c++ - 我可以通过更明确地消除类似 (myUnsigned >= MACRO_THAT_IS_ZERO) 的比较中的警告吗?

c - 如何在ubuntu中打印c程序的符号表?

c++ - 如何在 cppcheck 或 clang 中检查类型安全?

c - 是否可以从汇编文件中引用 C 枚举?