[英]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.