【发布时间】:2019-07-23 14:24:52
【问题描述】:
我有一个简单的程序,我可以使用 MinGW 的 C/C++ 库通过 clang 成功编译:
#include <stdio.h>
int main(int argc, char **argv) { printf("Hello world!\n"); return 0; }
我可以使用 mingw-gcc 成功编译:
$ gcc test.c -o test
$ ./test
Hello world!
我也可以使用 clang+mingw 成功编译:
$ clang test.c -o test -target
$ ./test
Hello world!
但是,如果我对我的程序(包括 float.h)做一个小改动,它会继续使用 gcc 编译,但不再使用 clang 编译:
#include <stdio.h>
#include <float.h>
int main(int argc, char **argv) { printf("Hello world!\n"); return 0; }
$ gcc test.c -o test
$ ./test
Hello world!
$ clang test.c -o test -target x86_64-pc-windows-gnu
In file included from test.c:2:
In file included from C:\llvm\built\lib\clang\8.0.0\include\float.h:45:
C:\mingw64-8.1.0\x86_64-w64-mingw32\include\float.h:28:15: fatal error: 'float.h' file not found
#include_next <float.h>
^~~~~~~~~
1 error generated.
clang 是否存在配置问题或缺少命令行参数?谷歌搜索了一下,似乎包含 float.h 时的路径顺序很重要,但这一切都应该由 clang 驱动程序在内部处理。
【问题讨论】:
-
有趣,我什至不知道 Clang 可以针对 windows :d
-
一个不同的环境,但我无法在 MSYS2 Mingw-w64 Win64 构建环境中重现该问题。
-
lib\clang\8.0.0\include\float.h:45 包含一个 ming 头文件 x86_64-w64-mingw32\include\float.h。 lib\clang\8.0.0\include\float.h 的第 45 行是什么?
-
@IanAbbott 这似乎适用于 C 示例,但 clang++ 似乎无法识别 msys gcc 包含路径,因此找不到 C++ 标头。
-
@effbiae #include_next