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

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

Please specify which file, on which branch, you’re talking about. As far as I can tell, libc++ hasn’t included a wrapper for putc since r249475 (roughly two years ago). -Eli

Hi Eli,

The “wrapper” is called ‘libcxx/include/stdio.h’, but I think that I have managed to get an SVN merge problem that is not properly resolved (though how far back I cannot tell) as I can clearly see that the new wrapper version of ‘<stdio.h>’ is a lot simpler than the one I have so this is a false negative. My apologies.

Thanks,

MartinO