libc++abi.dylib: terminate_handler unexpectedly threw an exception
上述的错误是我在拖拽Xib时出现的. 具体原因如下:
Even though Interface Builder is aware of a MyClass
, I get an error when starting the application.
This happens when MyClass
is part of a library, and does not happen if I compile the class directly in the application target.
Despite the "Unknown class MyClass in Interface Builder file." error printed at runtime, this issue has nothing to do with Interface Builder, but rather with the linker, which is not linking a class because no code uses it directly.
When the .nib data (compiled from the .xib) is loaded at runtime, MyClass
is referenced using a string, but the linker doesn't analyze code functionality, just code existence, so it doesn't know that. Since no other source files references that class, the linker optimizes it out of existence when making the executable. So when Apple's code tries to load such a class, it can't find the code associated with it, and prints the warning.
By default, Objective-C targets will have -all_load -ObjC
flags set by default, which will keep all of the symbols. But I had started with a C++ target, and didn't have that. Nevertheless, I found a way around this, which keeps the linker aggressive.
xcode5的解决方案:在 Build Phases --> Compile Sources 中添加这个类即可
如何在未使用arc的工程中引入一个使用了arc特性的文件:对相应的文件添加:-fobjc-arc参数
如何在arc工程中引用未使用arc的文件:对相应的文件添加:-fnoobjc-arc参数
http://superman474.blog.163.com/blog/static/1206614620125492042514/