iOS clang指令报错问题总结

主要记录自己日常使用 clang 报错的解决方案
通过指令将OC文件转换为C++文件
指令: xcrun -sdk iphoneos clang -arch arm64 -rewrite-objc 文件.m -o 文件-arm64.cpp

问题1

ViewController2.m进行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.

那是因为两个类没在同一个路径下, 将他们放在统一路径后即可通过


问题2

在类中使用了weakclang报错

/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++

你可能感兴趣的:(iOS clang指令报错问题总结)