为什么Clang 基本的c++代码不识别呢?编译一直报错

Xcode9.4 clang版本 如下:

MacB:WebTest zi$ clang -v
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

gcc如下:

MacB:WebTest zi$ gcc  -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

编译时如下:

MacB:WebTest zi$ make package
> Making all for tweak WebTest…
==> Preprocessing Tweak.xm…
==> Compiling Tweak.xm (arm64)…
Tweak.xm:1120:9: error: no template named 'variant'
typedef variant<int,char, double> MyDataAny;
        ^
1 error generated.

折腾一天,始终报错,无奈求救各位老师,谢谢

代码呢代码呢

MacB:WebTest zi$ gcc  -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1 
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

此处显示,c++/4.2.1,会不会是c++版本太低造成的呢???如何升级呢?
我google一下,好象和gcc没关系,实际编译都是clang完成的,那又不是什么原因造成的呢,clang版本太低????

谢谢

代码就是这行, 测试 HOOK c++:

typedef variant<int,char, double> MyDataAny;

MyDataAny (*old_Webr)(unsigned int,int);
MyDataAny new_Webr (unsigned int a ,int b )
{
NSLog(@“FFFFFFFFFFFF: 有了”);
return old_Webr(a,b);
}


MSHookFunction((void *)__xxxxxxxxxxxxxEjRi, (void *)&new_Webr, (void **)&old_Webr);

多谢张总!

您的include还有using namespace呢
std variant好像是cpp17加入的吧,是的话你得编辑Makefile切换到C++17

1 个赞

多谢张总老大,是这样切换吗?:
WebTest_CFLAGS += -Wno-error
WebTest_CFLAGS += -std=c++17 -stdlib=libc++
WebTest_LDFLAGS += -stdlib=libc++

加上这个,错误如下:

> Making all for tweak WebTest…
==> Preprocessing Tweak.xm…
==> Compiling Tweak.xm (arm64)…
Tweak.xm:1119:10: fatal error: 'variant' file not found
#include <variant>
         ^~~~~~~~~
1 error generated.

xcode-select -print-path 看一下

???

Xcode9太老了,这个版本没带std variant吧

有可能,多谢老大,我升级一下试试