macos Clang OS X Lion,找不到 cstdint
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10116724/
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
Clang OS X Lion, cannot find cstdint
提问by agmcleod
I'm trying to compile an application that utilizes cstdint. Since Apple deprecated the gcc, I wanted to try compiling it with clang, but i get the error:
我正在尝试编译一个使用 cstdint 的应用程序。由于 Apple 弃用了 gcc,我想尝试用 clang 编译它,但出现错误:
fatal error: 'cstdint' file not found
I know that the gcc 4.6.2 version has the option for -std=c++0x
, to include the library, but since the os x version is 4.2 that's not much of an option here. Any suggestions on how I can move forward? I have tried to install 4.6.2, but ran into a variety of issues when compiling some of the needed libraries before building gcc.
我知道 gcc 4.6.2 版本可以选择-std=c++0x
, 来包含库,但是由于 os x 版本是 4.2,所以这里的选项不多。关于我如何前进的任何建议?我尝试安装 4.6.2,但是在构建 gcc 之前编译一些所需的库时遇到了各种问题。
采纳答案by wkl
Presumably, you have the source code to this application, so you can modify the headers to include the correct cstdint
header, as Clang 3.0 (which Lion's tools come with) does have the header.
据推测,您拥有此应用程序的源代码,因此您可以修改标头以包含正确的cstdint
标头,因为 Clang 3.0(Lion 的工具随附)确实具有标头。
Quick Solution
快速解决方案
The header is under the tr1
directory, so you will want to do either of these includes:
标题位于tr1
目录下,因此您需要执行以下任一操作,包括:
#include <tr1/cstdint>
Or
或者
#include <stdint.h> // which will use the C99 header
Longer, boring explanation
更长,无聊的解释
After doing some additional reading since I remember you can do this without the tr1 directory:
在做了一些额外的阅读之后,我记得你可以在没有 tr1 目录的情况下做到这一点:
By default, you are going to be including C++ headers from /usr/include/c++/4.2.1
, which are the GNU GCC headers. /usr/include/c++/4.2.1/tr1
includes the TR1 header files, like cstdint
.
默认情况下,您将包含来自 的 C++ 标头/usr/include/c++/4.2.1
,它们是 GNU GCC 标头。/usr/include/c++/4.2.1/tr1
包括 TR1 头文件,如cstdint
.
The alternative method is to compile using the Clang++ frontend and passing the -stdlib=libc++
flag, which will use the headers from /usr/include/c++/v1
, which are Clang's C++ header implementations. It has cstdint
.
另一种方法是使用 Clang++ 前端进行编译并传递-stdlib=libc++
标志,这将使用来自 的标头/usr/include/c++/v1
,这是 Clang 的 C++ 标头实现。它有cstdint
。
Example:
例子:
// file called example.cxx
#include <tr1/cstdint>
int main() {
// whatever...
}
Compile this with:
编译这个:
g++ example.cxx
or
或者
clang++ example.cxx
And it will do what you want.
它会做你想做的。
If you don't want to use the tr1
version (which is roughly the same, if not exactly):
如果您不想使用该tr1
版本(大致相同,如果不完全相同):
// file called example.cxx
#include <cstdint>
int main() {
// stuff
}
This is compiled like this:
这是这样编译的:
clang++ -stdlib=libc++ example.cxx
Though if you use -stdlib=libc++
, it means you're linking to Clang's C++ library libc++
, rather than GCC's libstdc++
.
但是,如果您使用-stdlib=libc++
,则意味着您正在链接到 Clang 的 C++ 库libc++
,而不是 GCC 的libstdc++
.