更新到 iPhone SDK 4.0 后,链接器错误(仅模拟器)与自己的库

Linker error (only simulator) with own library after update to iPhone SDK 4.0(更新到 iPhone SDK 4.0 后,链接器错误(仅模拟器)与自己的库)

本文介绍了更新到 iPhone SDK 4.0 后,链接器错误(仅模拟器)与自己的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近更新到 iPhone SDK 4.0 并且不再能够为 iPhone 模拟器构建我的项目.问题是 ld 无法再找到我自己的一个库的类:

I recently updated to iPhone SDK 4.0 and are no longer able to build my project for the iPhone simulator. The problem is that classes of one of my own libraries can no longer be found by ld:

"_OBJC_CLASS_$_Book", referenced from:
   objc-class-ref-to-Book in Category.o
   (maybe you meant: ...)
ld: symbol(s) not found
collect2: ld returned 1 exit status

我已经阅读了一些关于类似问题的其他帖子,例如这里.不幸的是",我的问题与SDK框架无关,而是与我自己的lib有关,所以这里提到的解决方案不适用.

I already read some other posts about similar problems, like e.g. here. "Unfortunately", my problem has nothing to do with a SDK framework, but with my own lib, so the solutions mentioned there are not applicable here.

该库包含在我的目标的Link Binary With Libraries"下,库搜索路径是正确的(使用 XCode 和直接在我的项目文件中使用纯文本编辑器进行检查)并正确添加到 gcc 命令中.

The library is included under "Link Binary With Libraries" of my target, library search paths are correct (checked this with XCode and with a plain text editor directly in my project file) and correctly added to the gcc command.

我使用 iPhone Simulator 3.2 作为基础 SDK,但 SDK 4.0 也会出现同样的问题.同样,这适用于我的设备目标,但不适用于我的模拟器目标.不过,在我从 iPhone SDK 3.2 更新到 4.0 之前,它两者都适用.通过创建一个只有一个文件和链接库的新项目,我还能够重现此错误.但是,在我更新 XCode 和我的 SDK 之前,该库应该可以与模拟器 3.2 一起使用.

I'm using iPhone Simulator 3.2 as Base SDK, but the same problem occurs with SDK 4.0. Again, this works with my device target but not with my simulator target. It worked with both, though, before I updated from iPhone SDK 3.2 to 4.0. I was also able to reproduce this error by creating a new project with only one file and the linked lib. However, the lib should be okay as it worked with simulator 3.2 before I updated XCode and my SDK.

更多信息:Mac OS X 10.6.3、XCode 3.2.3 64 位、iPhone OS 3.2、GCC 4.2

More Facts: Mac OS X 10.6.3, XCode 3.2.3 64-Bit, iPhone OS 3.2, GCC 4.2

任何帮助将不胜感激.


Any help would be highly appreciated.


重新安装 SDK 3.2 后,一切都再次按预期运行.必须注意,文件夹/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs 中的 SDK 会被每次安装覆盖.然后我再次尝试重新安装 SDK 4.0 并出现与上述相同的错误.我没有在我的项目中进行任何更改,并且始终使用 3.2 作为 Base SDK.

After reinstalling SDK 3.2, everything worked as expected again. It must be noted, that the SDKs in folder /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs are overwritten with each installation. I then tried to reinstall SDK 4.0 again and the same error as above occurred. I didn't change anything in my project and always used 3.2 as Base SDK.

因此,问题可能会缩小到以下选项:

The problem can therefore possibly be narrowed down to the following options:

  • 苹果改变了某事.在导致问题的 Simulator SDK 3.2 中
  • XCode 3.2.3 中的更改导致了问题
  • 在构建我自己的库时出现错误/缺少编译器标志(但是,这些标志只会导致更改后的 SDK 或更改后的 IDE 出现问题)

我还在/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.2.sdk 上为这个文件夹的旧版本和新版本做了一个文件夹差异.事实证明,在相同"的 SDK 中实际上存在细微的变化.不过,我仍然认为这是一个 IDE/编译器标志问题.

I also did a folder diff on /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.2.sdk for both the old and the new version of this folder. It turned out that there are actually minor changes within the "same" SDK. I still think it's an IDE/compiler flag problem, though.

有人有什么想法吗?我不想永远坚持3.2...

Anybody any ideas? I don't want to stick to 3.2 forever...

推荐答案

我终于能够弄清楚我的编译器调用中缺少哪些标志来构建我的 lib.所以,回答我的问题:如果有人在将他/她自己的静态库链接到 XCode 3.2.3 中的目标(使用 iPhoneSimulator3.2.sdk 或 iPhoneSimulator4.0.sdk)时遇到问题,您需要使用以下内容构建您的库两个标志:

I was finally able to figure out which flags were missing in my compiler call to build my lib. So, to answer my question: If anybody has problems linking his/her own static lib to a target in XCode 3.2.3 (using iPhoneSimulator3.2.sdk or iPhoneSimulator4.0.sdk), you need to build your lib with the following two flags:

-fobjc-abi-version=2

-fobjc-abi-version=2

-fobjc-legacy-dispatch

-fobjc-legacy-dispatch

再次感谢 PhoneyDeveloper 的 他的提示.

这篇关于更新到 iPhone SDK 4.0 后,链接器错误(仅模拟器)与自己的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:更新到 iPhone SDK 4.0 后,链接器错误(仅模拟器)与自己的库

基础教程推荐