GData 静态库:使用 -fno-objc-arc 从 ARC 中排除文件?

发布于 2024-12-18 22:06:52 字数 535 浏览 5 评论 0原文

我在使用 ARC 的应用程序中使用 GData 静态库。谷歌的说明说将头文件从库链接到项目目标。

问题是,当我这样做时,我会收到编译器错误,因为 GData 库与 ARC 不兼容。

谷歌声明:

ARC 兼容性

当库源文件直接编译到使用 ARC 的项目中时,必须专门针对库源禁用 ARC。

要在 Xcode 4 中对源文件禁用 ARC,请在 Xcode 中选择项目和目标。在目标“Build Phases”选项卡下,展开 Compile Sources 构建阶段,选择库源文件,然后按 Enter 打开编辑字段,然后键入 -fno-objc-arc 作为编译器标志对于这些文件。

参考

但是由于我只有头文件,所以我不能在应用程序目标中使用此标志。

I am using the GData static library in my app that uses ARC. Google's instructions say to link the header files from the library to the project target.

The problem is that when I do so I get compiler errors as the GData library is not compatible with ARC.

Google states that:

ARC Compatibility

When the library source files are compiled directly into a project that uses ARC, then ARC must be disabled specifically for the library sources.

To disable ARC for source files in Xcode 4, select the project and the target in Xcode. Under the target "Build Phases" tab, expand the Compile Sources build phase, select the library source files, then press Enter to open an edit field, and type -fno-objc-arc as the compiler flag for those files.

(reference)

But since I have only the header files I can not use this flag in the app target.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许一世地老天荒 2024-12-25 22:06:52

嗯,我问了一下,10 分钟后就发现了。无论如何,如果它会对某人有所帮助:

  1. 问题仅在于 .h 文件,Goole 评论仅适用于您嵌入库而不是静态库的情况。
  2. 有人向谷歌报告问题后,他们添加了解决问题的新宏,方法如下:

在头文件中搜索名为:GDataDefines.h 的文件
并在其中添加以下代码:

//
// Simple macros to allow building headers for non-ARC files
// into ARC apps
//

#ifndef GDATA_REQUIRES_ARC
#if defined(__clang__)
#if __has_feature(objc_arc)
#define GDATA_REQUIRES_ARC 1
#endif
#endif
#endif

#if GDATA_REQUIRES_ARC
#define GDATA_UNSAFE_UNRETAINED __unsafe_unretained
#else
#define GDATA_UNSAFE_UNRETAINED
#endif

然后在导致 ARC 错误的 GDataObject.h 中将

GDataDescriptionRecord 结构更改为

   typedef struct GDataDescriptionRecord {
       NSString GDATA_UNSAFE_UNRETAINED *label;
       NSString GDATA_UNSAFE_UNRETAINED  *keyPath;
       GDataDescRecTypes reportType;
   } GDataDescriptionRecord;

并且

   __weak GDataObject *parent_;  // parent in tree of GData objects

   GDataObject GDATA_UNSAFE_UNRETAINED *parent_;

这是 google 更新的链接:
http://code.google.com/p/gdata -objectivec-client/source/detail?r=712

就是这样。

希望它能帮助别人

沙尼

Well I asked and found the unswear 10 minutes later. Any way if it will help someone:

  1. The problem is only with the .h files, Goole remark is only for cases you embed the library not as static library.
  2. After someone reported the problem to google, they added new macros that solve the problem, this is how:

search the header files for file named : GDataDefines.h
and add this code inside:

//
// Simple macros to allow building headers for non-ARC files
// into ARC apps
//

#ifndef GDATA_REQUIRES_ARC
#if defined(__clang__)
#if __has_feature(objc_arc)
#define GDATA_REQUIRES_ARC 1
#endif
#endif
#endif

#if GDATA_REQUIRES_ARC
#define GDATA_UNSAFE_UNRETAINED __unsafe_unretained
#else
#define GDATA_UNSAFE_UNRETAINED
#endif

Then in the GDataObject.h which causes the ARC errors

Change the GDataDescriptionRecord struct to

   typedef struct GDataDescriptionRecord {
       NSString GDATA_UNSAFE_UNRETAINED *label;
       NSString GDATA_UNSAFE_UNRETAINED  *keyPath;
       GDataDescRecTypes reportType;
   } GDataDescriptionRecord;

And the

   __weak GDataObject *parent_;  // parent in tree of GData objects

to

   GDataObject GDATA_UNSAFE_UNRETAINED *parent_;

This is the link to google update:
http://code.google.com/p/gdata-objectivec-client/source/detail?r=712

That's it.

Hope it will help someone

Shani

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文