主要記錄自己日常使用 clang 報錯的解決方案
通過指令將OC文件轉(zhuǎn)換為C++文件
指令: xcrun -sdk iphoneos clang -arch arm64 -rewrite-objc 文件.m -o 文件-arm64.cpp
問題1
對ViewController2.m進(jìn)行clang指令時報錯, 因為ViewController2.m引用了'Person.h' 頭文件;
warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
ViewController2.m:10:9: fatal error: 'Person.h' file not found
#import "Person.h"
^~~~~~~~~~
1 warning and 1 error generated.
那是因為兩個類沒在同一個路徑下, 將他們放在統(tǒng)一路徑后即可通過

問題2
在類中使用了weak后clang報錯
/var/folders/x9/_266tpqd76sb1c4cm_mvpjz40000gn/T/ViewController2-aab8a2.mi:55408:24: error: cannot create __weak reference because the current deployment target does not support weak references
__attribute__((objc_ownership(weak))) Person *weakPerson2 = person2;
^
/var/folders/x9/_266tpqd76sb1c4cm_mvpjz40000gn/T/ViewController2-aab8a2.mi:55421:20: error: cannot create __weak reference because the current deployment target does not support weak references
__attribute__((objc_ownership(weak))) Person *weakPerson2 = person2;
將指令指定運行時版本, 支持ARC后再次clang
xcrun -sdk iphoneos clang -arch arm64 -rewrite-objc -fobjc-arc -fobjc-runtime=ios-9.0 文件.m
參考文章:
把OC代碼 編譯成C/C++