Vinoth Kumar
Vinoth Kumar

Reputation: 57

iOS new Extension: clang: error: no such file or directory: '_NSExtensionMain'

I have created a new extension for an iOS project. On compilation, I am facing below error. Any idea what is happening?

clang: error: no such file or directory: '_NSExtensionMain'
Command Ld failed with a nonzero exit code

Pretty Printed complete error message:

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]

Upvotes: 1

Views: 1395

Answers (1)

Vinoth Kumar
Vinoth Kumar

Reputation: 57

As mentioned in this answer, I had an unknown flag under Build Settings -> Other Linker flags, that confused the linker. In my case, below were my Other Linker flags. In which, flags -weak-lSystem, -force_load did not have any input. So the linker considered subsequent parameter -e _NSExtensionMain as input to the previous flags. Linking and Compilation were successful after removing those 2 flags.

 -weak_framework CoreFoundation 
    -weak_framework UIKit 
    -weak_framework AVFoundation 
    -weak_framework CoreMedia 
    -weak-lSystem 
    -force_load
    -e _NSExtensionMain

Upvotes: 1

Related Questions