[cfe-dev] [LibC++] Incompatibility between '<stdio.h> from LibC++ v5.0's ' Newlib v2.5.0, and a workaround/fix

ORiordan, Martin via cfe-dev cfe-dev at lists.llvm.org
Thu Sep 21 08:07:33 PDT 2017


I have been working on stabilising our out-of-tree sources following the upgrade to the v5.0 Final Release, and came across an incompatibility between the '<stdio.h>' provided with Newlib v2.5.0 and the one provided with LibC++ v5.0.

The problem is how LibC++ handles the 'getc' and 'putc' implementations, and if these are defined it uses a shim, then '#undef's the original, and redefines them as functions.

In general this is a good strategy, but in this case 'getc' and 'putc' are both declared as external functions, and subsequently defined as macros.  When LibC++ undefines these macros and defines the functions 'getc' and 'putc', it does so appending '_NOEXCEPT' and this causes a multiple definition conflict with the declaration in Newlib's '<stdio.h>' which does not have this appended.

My workaround was to rewrite these as:

#ifndef __NEWLIB__
int getc(FILE *__lcpp_x) _NOEXCEPT {
#else
int getc(FILE *__lcpp_x)
#endif
and:
#ifndef __NEWLIB__
int petc(int __lcpp_x, FILE *__lcpp_y) _NOEXCEPT {
#else
int petc(int __lcpp_x, FILE *__lcpp_y)
#endif

All the best,

            MartinO


--------------------------------------------------------------
Intel Research and Development Ireland Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
Registered Number: 308263


This e-mail and any attachments may contain confidential material for the sole
use of the intended recipient(s). Any review or distribution by others is
strictly prohibited. If you are not the intended recipient, please contact the
sender and delete all copies.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170921/31ddb539/attachment.html>


More information about the cfe-dev mailing list