8

我正在 Linux 上用 C++ 开发一个程序。gcc 版本是 4.5.1 20100924。我想在我的程序中使用 std::atomic_int。我已经包含了原子头,如下所示:

include <atomic>

当我编译程序时,出现以下错误:

In file included from /usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomic_base.h:87:0,
                 from /usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/atomic:41,
                 from ../Source/Main.h:33:
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomicfwd_cxx.h:107:25: error: ‘char16_t’ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomicfwd_cxx.h:107:33: error: template argument 1 is invalid
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomicfwd_cxx.h:107:53: error: invalid type in declaration before ‘;’ token
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomicfwd_cxx.h:110:25: error: ‘char32_t’ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomicfwd_cxx.h:110:33: error: template argument 1 is invalid
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomicfwd_cxx.h:110:53: error: invalid type in declaration before ‘;’ token

如果我包括<cstdint>,我会得到同样的错误。标题 uchar.h 和 cuchar.h 在我的系统上不存在。如何解决编译错误?

先感谢您。

4

2 回答 2

8

编辑:

我错了。只需传递--std=c++0x给 g++,就可以了。

于 2012-07-31T14:09:57.837 回答
7

You seem to not have enabled C++11 support in your compiler or you use a compiler that has these new types not declared.

For char16_t and char32_t, you need no extra include.


g++ howto:

Type g++ --version. If it is at least 4.4, then it has support for new string literals. If not: You need a newer compiler version.

Then, make sure to pass --std=c++0x or --std=c++11 to the compiler.

于 2012-07-31T14:13:40.753 回答