Windows 上的叮当声
首先,我遵循了“入门:构建和运行 Clang”。特别是,我根据“使用 Visual Studio”部分构建了它。换句话说,我使用 Visual Studio 2010 构建了它。
其次,我手动设置了 MinGW 发行版的包含路径和库路径:
我正在尝试编译的简单程序:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
我从编译器得到以下反馈:
In file included from C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\iostream:39:
In file included from C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\ostream:39:
In file included from C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\ios:38:
In file included from C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\iosfwd:41:
In file included from C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\bits/postypes.h:41:
C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\cwchar:144:11: error: no member named 'fgetws' in the global namespace
using ::fgetws;
~~^
C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\cwchar:146:11: error: no member named 'fputws' in the global namespace
using ::fputws;
~~^
C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\cwchar:150:11: error: no member named 'getwc' in the global namespace
using ::getwc;
~~^
C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\cwchar:151:11: error: no member named 'getwchar' in the global namespace
using ::getwchar;
~~^
C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\cwchar:156:11: error: no member named 'putwc' in the global namespace
using ::putwc;
~~^
C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\cwchar:157:11: error: no member named 'putwchar' in the global namespace
using ::putwchar;
~~^
6 errors generated.
Build error occurred, build is stopped
Time consumed: 646 ms.
明显的问题是 - 为什么我会得到这个?
另外,我想了解更多细节,因为 Clang 网站提供了非常简短的信息 - 我认为有人可以向我澄清以下问题:
- 据我了解,Clang 没有自己的标准库(我猜是 stdc++,不是吗?)。这就是为什么我必须使用 MinGW 的标头和库 - 我是对的吗?
- 使用 Visual Studio 和 MinGW 构建 Clang 有什么区别?
- 我是否必须在
clang/lib/Frontend/InitHeaderSearch.cpp
中硬编码包含路径,或者我可以跳过它,而是稍后通过“-I”选项指定这些路径,就像我在上面的屏幕截图中所做的那样?
First of all, I've followed "Getting Started: Building and Running Clang". In particular, I've built it according to "Using Visual Studio" section. In other words, I've built it using Visual Studio 2010.
Secondly, I've manually set include and library paths to MinGW distribution:
The simple program I'm trying to compile:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
I get the following feedback from the compiler:
In file included from C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\iostream:39:
In file included from C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\ostream:39:
In file included from C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\ios:38:
In file included from C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\iosfwd:41:
In file included from C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\bits/postypes.h:41:
C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\cwchar:144:11: error: no member named 'fgetws' in the global namespace
using ::fgetws;
~~^
C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\cwchar:146:11: error: no member named 'fputws' in the global namespace
using ::fputws;
~~^
C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\cwchar:150:11: error: no member named 'getwc' in the global namespace
using ::getwc;
~~^
C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\cwchar:151:11: error: no member named 'getwchar' in the global namespace
using ::getwchar;
~~^
C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\cwchar:156:11: error: no member named 'putwc' in the global namespace
using ::putwc;
~~^
C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\cwchar:157:11: error: no member named 'putwchar' in the global namespace
using ::putwchar;
~~^
6 errors generated.
Build error occurred, build is stopped
Time consumed: 646 ms.
The obvious question is - why do I get this?
Additionally, I would like to know more details, and since, Clang website provides extremely brief information - I thought that somebody could clarify the following questions to me:
- As far as I understand Clang does not have its own standard library (stdc++ I guess, isn't it?). That's why I have to use MinGW's headers and libraries - am I right?
- What is the difference between building Clang with Visual Studio and MinGW?
- Do I have to hard-code include paths in
clang/lib/Frontend/InitHeaderSearch.cpp
or I can skip it and rather specify those paths later through "-I" option as I do in the screenshot above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 MSVS 构建 Clang,它将自动搜索默认的 VS 包含路径,并提取这些标头。这就是 libstdc++ 标头产生错误的原因:它们导入 VS 标头中不存在的 C 函数。目前,在 VS 中使用 Clang for C++ 是不行的:由于 Clang 中缺少 ABI(名称修改和其他)功能,您将出现链接失败。如果您仍想使用 MSVS Clang,请勿将其指向 MinGW 标头。它将解析 VS 标头(包括 C++),只是链接失败。
编辑:我已经构建了一个 dw2 版本的 GCC(仅限 32 位)以及 Clang。异常在此版本中起作用,因此您现在可以在 Windows 上使用 Clang 构建真正的 C++ 内容。 在此处获取版本 3.2。
If you build Clang with MSVS, it will automatically search the default VS include paths, and pull in those headers. This is the reason the libstdc++ headers are producing errors: they are importing C functions not present in the VS headers. Using Clang for C++ with VS is for now a no-go: you will get link failures due to missing ABI (name mangling and others) functionality in Clang. If you still want to use the MSVS Clang, don't point it to MinGW headers. It will parse the VS headers (including C++), it just will fail to link.
EDIT: I have built a dw2 version of GCC (32-bit only) accompanied by Clang. Exceptions work in this build, and so you can build real C++ stuff with Clang now on Windows. Get version 3.2 here.
明显的答案是你忘记发送 -fno-ms-compatibility 到 clang++ :P
我正在使用 VS 进行 Windows 应用程序开发,并使用 clang+CodeBlocks 来共享与平台域无关的方面。
The obvious answer is you forgot sending -fno-ms-compatibility to clang++ :P
I'm doing windows app dev using VS and use clang+CodeBlocks for sharing aspects neutral to platform's domain.