Why do I get errors about wchar_t when linking code built with RealView?

Question

When I try to link code built with RealView ® with code built with Sourcery CodeBench, I get a warning about wchar_t. What should I do?

Answer

RealView defines wchar_t as a 16-bit type. Sourcery CodeBench defines wchar_t as a 32-bit type. Both choices are allowed by the ABI for the ARM Architecture, so neither choice is "wrong". The linker notices the mismatch and issues a warning such as this to keep you from accidentally linking incompatible code:

(object.o) uses 4-byte wchar_t yet the output is to use 2-byte wchar_t;
use of wchar_t values across objects may fail

If you want RealView to use a 32-bit type for wchar_t, to match GCC, use the --wchar32 option to RealView.

If you want GCC to use a 16-bit wchar_t, for compatibility with RealView, use -fshort-wchar. Bear in mind that libraries provided with Sourcery CodeBench or by third parties may be incompatible with -fshort-wchar.

Alternatively, if you have verified that no wchar_t values are manipulated by both an object using 4-byte wchar_t and one using 2-byte wchar_t, you may disable the warning using the GCC option -Wl,--no-wchar-size-warning.


This entry was last updated on 8 March 2013.