合并ARC和非ARC文件不起作用

3
一旦我在Build Phases中的一个或多个单独文件中添加了-fno-objc-arc标志,我的MyProject-Prefix.pch文件就会被抛入非ARC模式,导致出现150个警告,如“警告:未指定'assign'、'retain'或'copy'属性-'assign'被假定”。下面是编译MyProject-Prefix.pch时的clang日志输出。您可以看到,-fobjc-arc标志出现了,但稍后,-no-fobjc-arc被添加,我认为这会覆盖ARC。只有当我在Build Phases中的单个.m源文件中添加-fno-objc-arc(每个人都建议混合使用ARC和非ARC文件)时才会发生这种情况。您有什么想法吗?
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c-header -arch i386 -fmessage-length=0 -std=gnu99 -fobjc-arc -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wreturn-type -Wno-implicit-atomic-properties -Wformat -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-sign-compare -Wno-shorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wno-undeclared-selector -Wno-deprecated-implementations -DDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -fexceptions -fasm-blocks -Wprotocol -Wdeprecated-declarations -mmacosx-version-min=10.6 -g -Wno-conversion -Wno-sign-conversion -fobjc-abi-version=2 -fobjc-legacy-dispatch "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -D__IPHONE_OS_VERSION_MIN_REQUIRED=50100 -iquote /Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Intermediates/MyProject.build/Debug-iphonesimulator/MyProject.build/MyProject-generated-files.hmap -I/Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Intermediates/MyProject.build/Debug-iphonesimulator/MyProject.build/MyProject-own-target-headers.hmap -I/Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Intermediates/MyProject.build/Debug-iphonesimulator/MyProject.build/MyProject-all-target-headers.hmap -iquote /Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Intermediates/MyProject.build/Debug-iphonesimulator/MyProject.build/MyProject-project-headers.hmap -iquoteOAuth2Client -iquoteOAuth2Client/Sources -iquoteOAuth2Client/Sources/OAuth2Client -I/Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Products/Debug-iphonesimulator/include -I../../Source/facebook-ios-sdk/src -I/Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Products/Debug-iphonesimulator/../three20 -I/Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Products/Debug-iphonesimulator/../../three20 -I../../Source/three20/Build/Products/three20 -I/Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Intermediates/MyProject.build/Debug-iphonesimulator/MyProject.build/DerivedSources/i386 -I/Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Intermediates/MyProject.build/Debug-iphonesimulator/MyProject.build/DerivedSources -F/Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Products/Debug-iphonesimulator -F/Users/steve/Desktop/MyProject/YelpAPI/Frameworks -fno-objc-arc --serialize-diagnostics /Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Intermediates/PrecompiledHeaders/MyProject-Prefix-eouuweehlrhtjxdsrgwseamnhnna/MyProject-Prefix.pch.dia -c /Users/steve/Desktop/MyProject/MyProject/MyProject-Prefix.pch -o /Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Intermediates/PrecompiledHeaders/MyProject-Prefix-eouuweehlrhtjxdsrgwseamnhnna/MyProject-Prefix.pch.pth -MMD -MT dependencies -MF /Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Intermediates/PrecompiledHeaders/MyProject-Prefix-eouuweehlrhtjxdsrgwseamnhnna/MyProject-Prefix.pch.d

你打开了 ARC 吗? Objective-C 自动引用计数变量设置为 YES? - IPaPa
你在哪些文件上设置了非 ARC? - Omar Abdelhafith
打开目标的构建设置并显示“级别”。这样,您就可以在目标基础上看到是否有任何有趣的设置在某个时候覆盖了ARC。-fno-obj-arc应该仅在文件基础上覆盖最终决策。 - Jesper
1
"Objective-C自动引用计数变量"已设置为是。升级级别也没有显示任何意外的东西:对于"Objective-C自动引用计数变量",只有全都是YES。一切都很好,直到我在主项目中添加单个-fno-objc-arc文件。我确实有非ARC的子项目,但它们不会干扰主项目的构建或ARC。 - Steve Simitzis
2个回答

5
这是可以预见的。很可能你的.pch文件包含一些定义,在非ARC模式下编译时会引起警告。最有可能的是,非ARC编译的文件也将使用预编译头文件,因此.pch文件中的头文件应该在ARC和非ARC模式下都可编译(毕竟,PCH机制在语义上等同于将.pch文件的#imports放入每个.m文件中)。
如果所有非ARC编译的文件都明确豁免了PCH编译模型,但XCode仍然给出这些警告,我会说这是XCode的一个错误。显然,你不能像MS的VisualC++那样关闭单个文件使用预编译头文件的功能,所以我唯一能给你的建议就是让你的.pch文件中的类适用于ARC和非ARC编译。

我刚遇到了同样的问题,但我找不到任何解决方法。我希望有一种方法可以针对单个文件关闭PCH。 - BGreenstone

2
当我试图标记我的两个.m文件时,我遇到了与你相同的错误。
-fno-objc-arc

我找不到解决方案,所以我只是将“Objective-C自动引用计数”变量设置为“否”,并添加了

-fobjc-arc 

为使用ARC的所有.m文件添加编译器标志。这对我很有效。


如果你无法将钉子从木板上拔出来,那就把木板从钉子上拆下来。 - uchuugaka

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接