linker command failed with exit code 1 (use -v to

2019-09-11 02:22发布

问题:

I am bulding my app in xcode 7, and get the following error:

ld: library not found for -lAFNetworking clang: error: linker command failed with exit code 1 (use -v to see invocation)

error

Cocoapods was used to load the necessary libraries in the app as follows:

# Uncomment this line to define a global platform for your project
platform :ios, '9.0'

target 'myapp' do
  # Uncomment this line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  pod 'AFNetworking', '~> 3.0'
  pod 'MBProgressHUD', '~> 0.9.2'
  pod 'Reachability', '~> 3.2'
  pod 'SDWebImage', '~> 3.8.1'
  pod 'ZipArchive', '~> 1.4.0'
  pod 'JDFTooltips', '~> 1.1'

end

what should I do?

回答1:

I had similar problem.

1) Clean DerivedData (~/Library/Developer/Xcode/DerivedData)

2) Product -> Clean -> Rebuild

3) Open Pods Targets and set Build Active Architecture Only - NO



回答2:

First of all, I would check to see if your podfile is in the same directory as your target.

If it is, delete the podfile.lock and the pods folder. (Leave the podfile alone.)

Clean the project (CMD+SHIFT+K). This may be unnecessary, but its usually worth doing just to be sure.

Then, do a pod install.

See if there are any warnings (yellow, not red text) in the terminal. Sometimes these warnings will prevent your project from building, and sometimes they won't. If your project won't build, and you do have warnings, try to fix them.

For example, there is a warning that mentions setting the build paths or something to $(inherited). I had one project that built fine with this warning, and another that required me to fix it.

I'm not guaranteeing this will work, but I think its a good first step.



回答3:

Did you change the name of your project?

Check this answer: ld: file not found: linker command failed with exit code 1 (use -v to see invocation)



回答4:

This also happened to me a lot, but i solved it by deleting the DerivedData folder of the project and related projects that was having problems, you can see how to simply do this by looking at this answer:

https://stackoverflow.com/a/37990186/3975501

Also this poses no risk to your application as DerivedData is just a folder that Xcode uses to reduce compiling time. If it's deleted Xcode will simply recreate it.



回答5:

I faced the same error while writing C using Xcode 8, The issue was there was a duplicate main method in two different files.

So, I commented one of them, then the error disappeared and the application started to compile successfully.