Help with compiling code with libcxx

Hi All,
   I compiled Qt with clang + libstdc++. Now using that, I'm trying to compile my code with clang + libc++. Now, one of the Qt headers is looking for std::bidirectional_iterator_tag by including <iterator>. This file does exist in libcxx/include and is picked up. However, <iterator> defines "bidirectional_iterator_tag" as:

_LIBCPP_BEGIN_NAMESPACE_STD

struct _LIBCPP_VISIBLE bidirectional_iterator_tag : public forward_iterator_tag {};

which is translated to:

namespace std {inline namespace __1 {
struct __attribute__ ((__visibility__("default"))) bidirectional_iterator_tag : public forward_iterator_tag {};

after pre-processing. So, the namespaces dont seem to match and clang compiles about incomplete type:

include/QtCore/qtconcurrentiteratekernel.h:154:60: error: variable has incomplete type 'std::bidirectional_iterator_tag'

Any idea how to resolve this? I tried to compile Qt (4.8.2) with clang + libc++ but ran into problems with missing <ext/atomicity.h> in libc++.

TIA,
ashok

Hi Ashok,

Any idea how to resolve this? I tried to compile Qt (4.8.2) with clang +
libc++ but ran into problems with missing <ext/atomicity.h> in libc++.

Qt should not be doing that, I've reported a bug a while ago [1].
Feel free to vote for it.

The workaround is simple: just replace that forward declaration (in
qiterator.h, AFAIK) with #include <iterator>

Please note that if you compile Qt with libstdc++ and compile your
code with libc++, you will not be able to pass STL containers and
other objects from Qt to your code -- they are not layout-compatible.
(For example, QVector::toStdVector() will return libstdc++
std::vector, which is not compatible with libc++ std::vector).

[1] https://bugreports.qt-project.org/browse/QTBUG-25960

Dmitri

Hi Ashok,

Any idea how to resolve this? I tried to compile Qt (4.8.2) with clang +
libc++ but ran into problems with missing<ext/atomicity.h> in libc++.

Qt should not be doing that, I've reported a bug a while ago [1].
Feel free to vote for it.

The workaround is simple: just replace that forward declaration (in
qiterator.h, AFAIK) with #include<iterator>

Thanks for the quick response and the solution.

Please note that if you compile Qt with libstdc++ and compile your
code with libc++, you will not be able to pass STL containers and
other objects from Qt to your code -- they are not layout-compatible.
(For example, QVector::toStdVector() will return libstdc++
std::vector, which is not compatible with libc++ std::vector).

I was thinking if this will work correctly and thought I'd give it a shot. So now I have to first compile Qt with libc++ and then my code with libc++. Thanks for the pointers, I've voted for the bug as well.

Any info on compiling Qt (4.8.2) with clang & libc++ ? I couldnt find replacements for things like "__gnu_cxx::__exchange_and_add()" being used in Qt.

TIA

Clang has C11 atomics:
http://clang.llvm.org/docs/LanguageExtensions.html#__c11_atomic

Dmitri

It also supports the full set of GNU atomic builtins, if using
_Atomic(...) types is impractical:

http://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/_005f_005fatomic-Builtins.html#_005f_005fatomic-Builtins

If I understand correctly, you are suggesting modifying Qt code and replace the __gnu_cxx::__exchange_and_add() and similar calls with libc++ variants, right?

Thanks again for the pointers.

If you are about QtWebKit code, feel free to just disable GCC clause of #ifdef
You may loose performance of atomiv operations in WebKit though.

It was in script, I've disabled script for now (our code uses the script functionality but I'll see how this goes).

thanks

That went through and now I have Qt compiled with clang & libc++ :). Thanks.