Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error 'char16_t and char32_t undeclared'

Tags:

c++

linux

std

gcc

g++

I am developing a program in C++ on Linux. The gcc version is 4.5.1 20100924. I want to use std::atomic_int in my program. I have included atomic header as below:

include <atomic>

When I compile the program I get below errors:

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

If I include <cstdint>, I get the same errors. The headers uchar.h and cuchar.h are not there on my system. How can I resolve the compilation errors?

Thank you in advance.

like image 815
geekowl Avatar asked Jul 31 '12 14:07

geekowl


2 Answers

EDITED:

I was wrong about that. just pass --std=c++0x to g++, and that would do it.

like image 141
starrify Avatar answered Nov 18 '22 15:11

starrify


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.

like image 37
Sebastian Mach Avatar answered Nov 18 '22 16:11

Sebastian Mach