Compile error “no type named std::u16string” when

2020-04-16 04:14发布

I am trying to build a c++ library depending on Qt using clang for iOS. My compile command is this:

xcrun --sdk iphoneos8.4 clang++ -Iinclude -I/Users/ls/projects/prompt-filesystem/src/../cpp_http -I/Users/ls/Qt/5.5/ios/include/QtNetwork -I/Users/ls/Qt/5.5/ios/include/QtCore -I/Users/ls/Qt/5.5/ios/include -std=c++11 -I/Users/ls/projects/haxe_libsodium/src/../dependencies/libsodium-ios/include -c -stdlib=libstdc++ -O2 -arch armv6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk -miphoneos-version-min=5.0 -Wno-parentheses -Wno-null-dereference -Wno-unused-value -Wno-bool-conversion -fno-stack-protector -DIPHONE=IPHONE -DIPHONEOS=IPHONEOS -DSTATIC_LINK -DHXCPP_VISIT_ALLOCS -DHXCPP_API_LEVEL=321 -I/usr/lib/haxe/lib/hxcpp/git/include -fexceptions -fstrict-aliasing -x c++ -Wno-invalid-offsetof /Users/ls/projects/prompt-filesystem/src/../cpp_http/QtHttp.cpp -oobj/iphoneos/e40135f5_QtHttp.o

The DHX... defines are because this is a hxcpp project. Now I am getting this build error:

In file included from /Users/ls/Qt/5.5/ios/include/QtNetwork/QNetworkAccessManager:1:
In file included from /Users/ls/Qt/5.5/ios/include/QtNetwork/qnetworkaccessmanager.h:37:
In file included from /Users/ls/Qt/5.5/ios/include/QtCore/QObject:1:
In file included from /Users/ls/Qt/5.5/ios/include/QtCore/qobject.h:41:
/Users/ls/Qt/5.5/ios/include/QtCore/qstring.h:739:55: error: no type named 'u16string' in namespace 'std'
static inline QString fromStdU16String(const std::u16string &s);

It is related to the fact that I am using c++11, but I want to do that because I need it at some other place.

The only suggestion I found was, that I should include "string" before including Qt. But I am doing that and it does not help.

标签: qt c++11 clang
1条回答
家丑人穷心不美
2楼-- · 2020-04-16 04:39

Your command-line option -stdlib=libstdc++ is using gcc-4.2's standard library. This is an ancient std::lib produced long before C++11. std::u16string is new with C++11.

Instead of -stdlib=libstdc++, try -stdlib=libc++.

查看更多
登录 后发表回答