我为一个iOS项目创建了一个新的扩展名。在编写上,我面临着以下错误。知道发生了什么吗?
clang: error: no such file or directory: '_NSExtensionMain'
Command Ld failed with a nonzero exit code
漂亮打印完整的错误信息:
Ld /Users/[Me]/Library/Developer/Xcode/DerivedData/[MyApp]/Build/Products/Debug-iphonesimulator/[MyApp].appex/[MyApp] normal (in target '[MyApp]' from project '[MyApp]')
cd /Users/[Me]/[MyRepo]
/Applications/Xcode_12.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-target x86_64-apple-ios14.2-simulator
-isysroot /Applications/Xcode_12.2.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.2.sdk
-L/Users/[Me]/Library/Developer/Xcode/DerivedData/[MyApp]/Build/Products/Debug-iphonesimulator
-F/Users/[Me]/Library/Developer/Xcode/DerivedData/[MyApp]/Build/Products/Debug-iphonesimulator
-filelist /Users/[Me]/Library/Developer/Xcode/DerivedData/[MyApp]/Build/Intermediates.noindex/[MyApp].build/Debug-iphonesimulator/[MyApp].build/Objects-normal/x86_64/[MyApp].LinkFileList
-Xlinker -rpath
-Xlinker @executable_path/Frameworks
-Xlinker -rpath
-Xlinker @executable_path/../../Frameworks -dead_strip
-Xlinker -object_path_lto
-Xlinker /Users/[Me]/Library/Developer/Xcode/DerivedData/[MyApp]/Build/Intermediates.noindex/[MyApp].build/Debug-iphonesimulator/[MyApp].build/Objects-normal/x86_64/[MyApp]_lto.o
-Xlinker -export_dynamic
-Xlinker -no_deduplicate
-Xlinker -objc_abi_version
-Xlinker 2 -fapplication-extension -fobjc-link-runtime -L/Applications/Xcode_12.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -L/usr/lib/swift
-Xlinker -add_ast_path
-Xlinker /Users/[Me]/Library/Developer/Xcode/DerivedData/[MyApp]/Build/Intermediates.noindex/[MyApp].build/Debug-iphonesimulator/[MyApp].build/Objects-normal/x86_64/[MyApp].swiftmodule
-weak_framework CoreFoundation
-weak_framework UIKit
-weak_framework AVFoundation
-weak_framework CoreMedia
-weak-lSystem
-force_load
-e _NSExtensionMain
-Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements
-Xlinker /Users/[Me]/Library/Developer/Xcode/DerivedData/[MyApp]/Build/Intermediates.noindex/[MyApp].build/Debug-iphonesimulator/[MyApp].build/[MyApp].appex-Simulated.xcent
-Xlinker -no_adhoc_codesign
-Xlinker -dependency_info -Xlinker /Users/[Me]/Library/Developer/Xcode/DerivedData/[MyApp]/Build/Intermediates.noindex/[MyApp].build/Debug-iphonesimulator/[MyApp].build/Objects-normal/x86_64/[MyApp]_dependency_info.dat
-o /Users/[Me]/Library/Developer/Xcode/DerivedData/[MyApp]/Build/Products/Debug-iphonesimulator/[MyApp].appex/[MyApp]
正如在这个答案中提到的,我在Build Settings -> Other Linker flags
下有一个未知的标志,这混淆了链接器。在我的例子中,下面是我的Other Linker flags
。其中,标志-weak-lSystem, -force_load
没有任何输入。因此,链接器将后面的参数-e _NSExtensionMain
视为前面标志的输入。删除这两个标志后,链接和编译成功。
-weak_framework CoreFoundation
-weak_framework UIKit
-weak_framework AVFoundation
-weak_framework CoreMedia
-weak-lSystem
-force_load
-e _NSExtensionMain