<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Nov 13, 2016 at 7:12 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><span class=""><div><div class="gmail_extra"><div class="gmail_quote">On 13 Nov 2016 5:27 pm, "Eric Fiselier via cfe-dev" <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br type="attribution"><blockquote class="m_-595880895048527392quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="m_-595880895048527392quoted-text">> <span style="font-size:12.8px">But I used -save-temps to create the algorithm.ii and searched for all</span><br style="font-size:12.8px"><div><span style="font-size:12.8px">> occurrences of 'extern "C" {' inside it and I can confirm there is not</span></div><div><span style="font-size:12.8px">> C++ header inside any 'extern C' block.</span><br style="font-size:12.8px"></div></div><div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Are you sure about that? libc++ provides its own version of each C library header as well (ex. <math.h>).</span></div><div><span style="font-size:12.8px">My best guess is that the system C library is included a libc++ C library wrapper inside an 'extern C' block.</span></div></div></div></blockquote></div></div></div><div dir="auto"><br></div></span><div dir="auto">Don't libc++'s .h headers all have an extern "C++" block to avoid that possibility?</div></div></blockquote><div><br></div><div>It seems some headers do, including <math.h>, but there are still others without it.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div dir="auto"><br></div><div dir="auto">There also doesn't seem to be any evidence of this in the #include stack reported by the compiler. It looks like maybe a system header ended with an extern "C" still open, or somehow libc++'s headers are being implicitly treated as "extern C" system headers (which get an explicit extern "C" wrapped around them).</div><div dir="auto"><br></div><div dir="auto">Alan, can you provide the preprocessed file produced by -save-temps?</div><div><div class="h5"><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="m_-595880895048527392quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><span style="font-size:12.8px">/Eric</span></div><div><span style="font-size:12.8px"><br></span></div></div></div><div class="m_-595880895048527392elided-text"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 7, 2016 at 10:17 AM, Alan Carvalho de Assis via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Everyone,<br>
<br>
I'm compiling the LLVM libcxx for NuttX RTOS (compiling on Linux to<br>
integrate it on NuttX).<br>
<br>
But it is failing with tons of these "error: template with C linkage" :<br>
<br>
make[1]: Entering directory '/home/alan/nuttxspace/nuttx/l<wbr>ibxx'<br>
CXX: libcxx/algorithm.cxx<br>
arm-none-eabi-g++ -c -Wall -Wshadow -Wundef -g -mcpu=cortex-m4<br>
-mthumb -mfloat-abi=soft -I. -isystem<br>
/home/alan/nuttxspace/nuttx/in<wbr>clude -isystem<br>
/home/alan/nuttxspace/nuttx/in<wbr>clude/cxx -isystem<br>
/home/alan/nuttxspace/nuttx/in<wbr>clude/libcxx -pipe -std=c++11<br>
-DCLOCK_MONOTONIC -D__NuttX__ -pedantic -D_DEBUG<br>
-D_LIBCPP_BUILD_STATIC libcxx/algorithm.cxx -o algorithm.o<br>
In file included from<br>
/home/alan/nuttxspace/nuttx/in<wbr>clude/libcxx/algorithm:639:0,<br>
from libcxx/algorithm.cxx:10:<br>
/home/alan/nuttxspace/nuttx/in<wbr>clude/libcxx/type_traits:397:1<wbr>: error:<br>
template with C linkage<br>
template <class _T1, class _T2> struct _LIBCPP_TYPE_VIS_ONLY pair;<br>
^<br>
/home/alan/nuttxspace/nuttx/in<wbr>clude/libcxx/type_traits:398:1<wbr>: error:<br>
template with C linkage<br>
template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY reference_wrapper;<br>
^<br>
/home/alan/nuttxspace/nuttx/in<wbr>clude/libcxx/type_traits:399:1<wbr>: error:<br>
template with C linkage<br>
template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash;<br>
^<br>
/home/alan/nuttxspace/nuttx/in<wbr>clude/libcxx/type_traits:401:1<wbr>: error:<br>
template with C linkage<br>
template <class><br>
^<br>
/home/alan/nuttxspace/nuttx/in<wbr>clude/libcxx/type_traits:404:1<wbr>: error:<br>
template with C linkage<br>
template <class _Tp><br>
^<br>
/home/alan/nuttxspace/nuttx/in<wbr>clude/libcxx/type_traits:407:1<wbr>: error:<br>
template with C linkage<br>
template <class _Tp, bool><br>
^<br>
/home/alan/nuttxspace/nuttx/in<wbr>clude/libcxx/type_traits:410:1<wbr>: error:<br>
template with C linkage<br>
template <bool _Bp, class _If, class _Then><br>
^<br>
/home/alan/nuttxspace/nuttx/in<wbr>clude/libcxx/type_traits:412:1<wbr>: error:<br>
template with C linkage<br>
template <class _If, class _Then><br>
^<br>
/home/alan/nuttxspace/nuttx/in<wbr>clude/libcxx/type_traits:419:1<wbr>: error:<br>
template with C linkage<br>
template <bool, class _Tp> struct _LIBCPP_TYPE_VIS_ONLY __lazy_enable_if {};<br>
^<br>
/home/alan/nuttxspace/nuttx/in<wbr>clude/libcxx/type_traits:420:1<wbr>: error:<br>
template with C linkage<br>
template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY<br>
__lazy_enable_if<true, _Tp> {typedef typename _Tp::type type;};<br>
^<br>
/home/alan/nuttxspace/nuttx/in<wbr>clude/libcxx/type_traits:422:1<wbr>: error:<br>
template with C linkage<br>
template <bool, class _Tp = void> struct _LIBCPP_TYPE_VIS_ONLY enable_if {};<br>
<br>
<br>
<br>
<br>
I searched on Internet and discovered that this error happens when<br>
there is some 'extern "C" { ' without the closing ' }' and then it<br>
wrap some C++ code.<br>
<br>
I saw this comment inside ctype.h :<br>
<br>
#ifdef __cplusplus<br>
#if defined(_LIBCPP_MSVCRT)<br>
// We support including .h headers inside 'extern "C"' contexts, so switch<br>
// back to C++ linkage before including these C++ headers.<br>
extern "C++" {<br>
#include "support/win32/support.h"<br>
#include "support/win32/locale_win32.h"<br>
}<br>
#endif // _LIBCPP_MSVCRT<br>
<br>
Although I'm not on MSVCRT, the comment explains why this error could happen.<br>
<br>
But I used -save-temps to create the algorithm.ii and searched for all<br>
occurrences of 'extern "C" {' inside it and I can confirm there is not<br>
C++ header inside any 'extern C' block.<br>
<br>
After many tests I noted that if I modify include/algorithm to include<br>
'extern "C++" {' :<br>
@@ -634,7 +634,10 @@ template <class BidirectionalIterator, class Compare><br>
<br>
#include <__config><br>
#include <initializer_list><br>
+extern "C++"<br>
+{<br>
#include <type_traits><br>
+}<br>
#include <cstring><br>
#include <utility> // needed to provide swap_ranges.<br>
#include <memory><br>
<br>
The issue disappear, but I want to discover the root caused instead of<br>
use an ugly hack.<br>
<br>
How I can discover where the error is happening, since -save-temps<br>
didn't show nothing wrong ?<br>
<br>
BR,<br>
<br>
Alan<br>
______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>
</div><br>______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div></div></div></div>
</blockquote></div><br></div></div>