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

[英]Combining ARC and non-ARC files not working


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文件。這對我有用。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/06/05/729b6a0c2dfeff569a091c2f67e72fb8.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com