简体   繁体   English

iPhone:在应用程序中使用静态库会使设备崩溃,但不会使iphone模拟器崩溃

[英]iPhone: Using static library in an application crashes the device but not the iphone simulator

I have a library I made, and now I want to utilize it in an application. 我有一个我制作的库,现在我想在应用程序中使用它。 I've believe I've properly linked to the library. 我相信我已正确链接到库。 Here are all the things I've done: 这是我所做的所有事情:

  • Set the header search path 设置标题搜索路径
  • Set other linker flags to "-ObjC" 将其他链接器标志设置为“ -ObjC”
  • Added the static library xcode project 添加了静态库xcode项目
  • Made sure the lib.a was listed as a framework target 确保将lib.a列为框架目标
  • Added the library as a direct dependency 将库添加为直接依赖项

Like I said in the title, I've successfully run the app with the static library in the simulator. 就像我在标题中说的那样,我已经使用模拟器中的静态库成功运行了该应用程序。 Once I try testing the app using the device, it crashes the second it has to use a function from the library: 一旦我尝试使用设备测试应用程序,它就会崩溃,这必须使用库中的函数:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSDate firstOfCurrentMonth]: unrecognized selector sent to class 0x3841bb44'
2009-10-10 12:45:31.159 Basement[2372:207] Stack:

This is due to a bug in the current SDK linker. 这是由于当前SDK链接程序中的错误所致。 See this post for more information on the problem and possible workarounds. 有关问题和可能的解决方法的更多信息,请参见此文章。 (also see this post .) (另请参阅这篇文章 。)

Update: 更新:

Another thing you can try is to remove the static library and include the library's source files directly in the application's project. 您可以尝试的另一件事是删除静态库,并将该库的源文件直接包含在应用程序的项目中。 I was facing a similar static library linking issue and that's what I ended up falling back on to get it to run successfully. 我遇到了一个类似的静态库链接问题,这就是我最终依靠它来使其成功运行的原因。 If that works (however gross a workaround it may be) then it's definitely a linker issue. 如果这行得通(尽管总有解决方法的话),那绝对是一个链接器问题。

I ran into this problem recently. 我最近遇到了这个问题。 I was unable to get the -all_load to work, when I noticed that another category I had DID work. 当我发现另一个类别的DID工作正常时,我无法使-all_load正常工作。 I was lazy for this category and included it in with another file. 我对于这个类别很懒,并把它包含在另一个文件中。

I eventually created a dummy class (no methods, instance variables) and included the implementation of my categories in the .m file for that dummy class. 我最终创建了一个哑类(没有方法,实例变量),并将该类的实现包含在该哑类的.m文件中。 After doing this my categories started working even after I removed the -all_load flag. 完成此操作后,即使删除了-all_load标志,我的类别也开始工作。

This was on iPhone OS 3.1.3. 这是在iPhone OS 3.1.3上。

This certainly is not the RIGHT way to fix it, but it seemed to work. 当然,这不是解决问题的正确方法,但似乎可行。

Full sample code is on my blog for my (trivial) categories. 我的(重要)类别的完整示例代码在我的博客上

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM