ARC和非ARC文件的组合不起作用

时间:2023-01-17 13:01:54

Once I add the -fno-objc-arc flag to one or more individual files in Build Phases, my MyProject-Prefix.pch file is thrown into non-ARC mode, causing 150 warnings like "warning: no 'assign', 'retain', or 'copy' attribute is specified - 'assign' is assumed" to be thrown.

一旦我将-fno-objc-arc标志添加到Build Phases中的一个或多个单独文件,我的MyProject-Prefix.pch文件就会被抛入非ARC模式,导致150个警告,例如“warning:no'assign','retain ',或'copy'属性被指定 - 'assign'被假定为“被抛出。

Here's the clang log output from compiling MyProject-Prefix.pch. As you can see, the -fobjc-arc flag appears, but later on, -no-fobjc-arc is added, which I'm assuming overrides ARC. This only happens if I add -fno-objc-arc to a single .m source file in Build Phases (the standard advice that everyone gets to mix ARC and non-ARC files).

这是编译MyProject-Prefix.pch的clang日志输出。如您所见,-fobjc-arc标志出现,但稍后会添加-no-fobjc-arc,我假设它会覆盖ARC。只有当我将-fno-objc-arc添加到Build Phases中的单个.m源文件时(每个人都可以混合ARC和非ARC文件的标准建议),才会发生这种情况。

Any ideas?

/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

2 个解决方案

#1


5  

This is only to be expected. Chances are high that your .pch file contains some definitions that would cause a warning when compiled in non-ARC mode. Most probably the non-arc compiled files will use the precompiled header, too, so the header in the .pch files should be compilable in both ARC and non-ARC mode (after all, the PCH mechanism is semantically equivalent to putting the #imports of the .pch file into each and every .m file).

这只是预料之中的。您的.pch文件包含一些定义会导致在非ARC模式下编译时出现警告的可能性很高。很可能非弧编译文件也会使用预编译的头文件,所以.pch文件中的头文件应该在ARC和非ARC模式下都可编译(毕竟,PCH机制在语义上等同于放入#imports将.pch文件放入每个.m文件中)。

I would say that this is a bug of XCode if it still gave these warning when all non-ARC compiled files were explicitly exempted from the PCH compilation model. Apparently you can't turn off the usage of pre-compiled headers for single files under XCode (as you can do with MS's VisualC++), so the only advice I can give you is to make the classes in your .pch file compatible for both ARC and non-ARC compilation.

我会说这是XCode的一个错误,如果它仍然在所有非ARC编译文件明确免除PCH编译模型时发出这些警告。显然你不能在XCode下关闭单个文件的预编译头文件的使用(就像你使用MS的VisualC ++一样),所以我能给你的唯一建议就是让你的.pch文件中的类兼容ARC和非ARC编译。

#2


2  

I got the same error you did when attempting to flag two of my .m files with

我在尝试使用标记我的两个.m文件时遇到了同样的错误

-fno-objc-arc

, and couldn't find a solution, so I just set the "Objective-C Automatic Reference Counting" variable to "No" and added the

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

-fobjc-arc 

compiler flag to all of the .m files which use ARC. This worked for me.

编译器标志到使用ARC的所有.m文件。这对我有用。

#1


5  

This is only to be expected. Chances are high that your .pch file contains some definitions that would cause a warning when compiled in non-ARC mode. Most probably the non-arc compiled files will use the precompiled header, too, so the header in the .pch files should be compilable in both ARC and non-ARC mode (after all, the PCH mechanism is semantically equivalent to putting the #imports of the .pch file into each and every .m file).

这只是预料之中的。您的.pch文件包含一些定义会导致在非ARC模式下编译时出现警告的可能性很高。很可能非弧编译文件也会使用预编译的头文件,所以.pch文件中的头文件应该在ARC和非ARC模式下都可编译(毕竟,PCH机制在语义上等同于放入#imports将.pch文件放入每个.m文件中)。

I would say that this is a bug of XCode if it still gave these warning when all non-ARC compiled files were explicitly exempted from the PCH compilation model. Apparently you can't turn off the usage of pre-compiled headers for single files under XCode (as you can do with MS's VisualC++), so the only advice I can give you is to make the classes in your .pch file compatible for both ARC and non-ARC compilation.

我会说这是XCode的一个错误,如果它仍然在所有非ARC编译文件明确免除PCH编译模型时发出这些警告。显然你不能在XCode下关闭单个文件的预编译头文件的使用(就像你使用MS的VisualC ++一样),所以我能给你的唯一建议就是让你的.pch文件中的类兼容ARC和非ARC编译。

#2


2  

I got the same error you did when attempting to flag two of my .m files with

我在尝试使用标记我的两个.m文件时遇到了同样的错误

-fno-objc-arc

, and couldn't find a solution, so I just set the "Objective-C Automatic Reference Counting" variable to "No" and added the

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

-fobjc-arc 

compiler flag to all of the .m files which use ARC. This worked for me.

编译器标志到使用ARC的所有.m文件。这对我有用。