简体   繁体   English

如何处理:重新声明C ++内置类型'char16_t'

[英]How to deal with: redeclaration of C++ built-in type ‘char16_t’

In a C++11 project I have to use external C library. 在C ++ 11项目中,我必须使用外部C库。 This library main header file defines 此库主头文件定义

typedef uint16_t        char16_t;  

And because of it compilation of the C++ program which includes this library fails, with the message: 因为它包含这个库的C ++程序的编译失败,消息:

redeclaration of C++ built-in type ‘char16_t’

The only idea I have is to repackage whole library but because char16_t is pervasive in this library it would be very time consuming (if even possible). 我唯一的想法就是重新打包整个库,但因为char16_t在这个库中很普遍,所以它非常耗时(如果可能的话)。 Are there some sensible ways of dealing with this problem? 是否有一些明智的方法来处理这个问题?

Edit: 编辑:

I have also another idea of removing problematic line and replacing every occurrence of char16_t with uint16_t but I would have to modify third party library headers and I do not particularly like this idea (there can be more similar errors). 我还有另一个想法是删除有问题的行并用uint16_t替换每个char16_t,但我必须修改第三方库头,我不是特别喜欢这个想法(可能有更多类似的错误)。 So I also wonder whether there is some good way of dealing of broader problem of incompatibilities between C++ and C when including headers. 所以我也想知道在包含头文件时是否有一些处理C ++和C之间不兼容问题的好方法。

You could use a macro to rename the library type while keeping it unrelated to the new language type char16_t : 您可以使用宏来重命名库类型,同时保持它与新语言类型char16_t无关:

#define char16_t LIBRARY_char16_t
#include <library>
#undef char16_t

Then, the library header will be compiled in your code base such that the typedef has the name LIBRARY_char16_t . 然后,库头将在您的代码库中编译,以便typedef具有名称LIBRARY_char16_t

The library itself is still compiled such that the type in question is typedef'ed to uint16_t so you should not attempt to change this (by eg removing the typedef) in order to stay binary-compatible with the compiled library. 库本身仍然编译,有问题的类型Typedef的到uint16_t所以你不应该试图改变这一点(例如通过去除的typedef),以保持与编译库二进制兼容。

C++11 defines char32_t and char16_t as built in types. C ++ 11将char32_t和char16_t定义为内置类型。 This error only happens if you are using C++11. 只有在使用C ++ 11时才会出现此错误。 ie in your Application.mk file you have: 即在您的Application.mk文件中,您有:

APP_CPPFLAGS += -std=c++11

You can either remove the C++11 support, OR use the following workaround, that should probably be a part of the official Android source (if not already). 您可以删除C ++ 11支持, 使用以下解决方法,这应该是官方Android源的一部分(如果还没有)。

in file /frameworks/native/include/utils/Unicode.h 在文件/frameworks/native/include/utils/Unicode.h中

#if __cplusplus <= 199711L
typedef uint32_t char32_t;
typedef uint16_t char16_t;
#endif

It is based on answers from a question about char16/32_t with C++11 它基于关于char16 / 32_t和C ++ 11的问题的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GLUT 问题:错误重新声明 C++ 内置类型 &#39;wchar_t&#39; - GLUT Problem: error redeclaration of c++ built-in type 'wchar_t' C ++ char16_t的大小取决于什么? - C++ What does the size of char16_t depend on? C ++内置类型&#39;wchar_t&#39;Windows 10 glut cpp的重新声明 - redeclaration of C++ built-in type 'wchar_t' windows 10 glut cpp 如何在C ++中将文件的内容读入char16_t数组? - How to read a file's contents into a char16_t array in C++? 使用用于C ++代码的标头编译C代码时,未知类型名称char16_t - Unknown Type name char16_t while compiling C code using a header that is used for C++ code Visual Studio C++ 2015 std::codecvt with char16_t 或 char32_t - Visual Studio C++ 2015 std::codecvt with char16_t or char32_t 在没有C ++ 11的情况下使用char16_t,char32_t等? - Using char16_t, char32_t etc without C++ 11? Dev C++ 中的 Glut 错误“重新声明 C++ 内置类型‘short’” - Glut in Dev C++ error “redeclaration of C++ built-in type `short'” 尝试研究出色的MPEG Layer-III编码器-获得“对C ++内置类型&#39;bool&#39;的重新声明” - Trying to study shine MPEG Layer-III encoder - getting “redeclaration of C++ built-in type 'bool'” C ++模板std :: array <char16_t, N> 隐藏N到模板展示? - C++ Templates std::array<char16_t, N> hide N to template impl?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM