18

I used Swift language in my IOS application project in Xcode6 Beta6 and then I had to work on it with another computer. Then I got this error:

"clang: error: linker command failed with exit code 1 (use -v to see invocation)"

This error is shown only different computers than the computer on which I opened my project at first. It does not give an error in the first computer (which I opened and started to the project)

I tried to clean, and delete the contents of DerivedData folder, but it gives me the same error again. Below this error, it also says that "file not found:" for inside of the DerivedData folder:

file not found: /Users/macbook/Library/Developer/Xcode/DerivedData/SihirliSayilar-gmmsqkhqgygosqeuqdiibnrjasbq/Build/Products/Debug-iphonesimulator/Project.app/Project

I looked the other titles for this issue, but none of them solve this problem. Thank you for any help!

Maxim Shoustin
  • 77,483
  • 27
  • 203
  • 225
simge
  • 259
  • 2
  • 5
  • 10

11 Answers11

32

The fact that it's a linker error should point you into the right direction. Compilation errors usually mean an error in your syntax. Linker error means that although your source files have been compiled correctly, but when the time comes to be linked with other frameworks (system frameworks, or 3rd party ones), clang cannot find them in place.

Usually, this is because a 3rd party library is missing from your system, and your project depends on it, and although it can find the header files, it cannot find the actual library file to connect to. The fact that transferring your project to other computers is giving you problems, while at your computer compiles and links correctly also strengthens the assumption that probably it's a problem with the environment you are trying to compile with and you need to install something.

To find out more about the issue, go into Xcode, go into the report navigator, and you will see logs of all the builds you have made. Check the first one (which is the last build). Scroll to the bottom, and see exactly why it didn't compile. The most common scenario is that some symbol could not be found. Check in which library this symbol belongs, then install this library to your system.

csotiriou
  • 5,653
  • 5
  • 36
  • 45
  • I tried what you said, it works, but now it gives me another error which says `Compilation failed for data model at path '/Users/macbook/Library/Developer/Xcode/DerivedData/SihirliSayilar-gmmsqkhqgygosqeuqdiibnrjasbq/Build/Products/Debug-iphonesimulator/SihirliSayilar.app/Project.momd/Project.mom'` – simge Aug 27 '14 at 22:17
  • This is an entirely different problem. .mom files are Core Data models. You probably have a malformed one. Are you sure that you have set all your data models correctly and assigned each core data property the correct value? BTW, since my answer helped you fix the problem, please accept it. – csotiriou Aug 28 '14 at 07:14
11

I got same error you have mentioned. I have just clean the project and build it. It worked!

You can clean the project in Product Tab and select clean. To build select build in product tab in Xcode.

Rahul Akula
  • 135
  • 1
  • 10
8

I encountered the same problem and my solution is as follow:

Close the current project in xcode ---> Go to your project file and open the project by clicking the .xcworkspace file. Note: not the .xodeproj file.

Hope this helps!

shudeng wu
  • 141
  • 1
  • 6
  • I tried 5 different methods and finally this one works. What's the difference between File->Open and double click .xcworkspace file to open? – hatted Aug 06 '17 at 04:27
  • For me too, Thanks! – Nuria Ruiz Nov 30 '17 at 09:58
  • Miracle of miracle worked for me too. I got this error after installing Realm with Cocoa Pods. Now OK. Interestingly due to a change in Xcode and iOS and Swift the easy install of Realm may not work (drag and drop 2 Realm files into binary files). However! Using cocoa pods to install Realm works presumably because it compiles Re Realm Files. Just a happy amateur without linker issues and presumably with realm installed and without errors. Anyone wishes further info contact me glennmd@gmail.com happy to help. – Glenn Tisman Apr 01 '18 at 01:04
6

In My case it worked like this:

-> Click on the project
-> Go to "General" tab down there
-> Go to "Linked Frameworks & Libraries"
-> Click of the "+" button , you will find something like this -> Pods_yourProjectname.framework add it
-> Then add the Frameworks that you have added from there only!
-> "Command+B" (Build your Project) and the combination "Shift+Command+K" (Clean your Project)
-> Run your Application.

benomatis
  • 5,536
  • 7
  • 36
  • 59
Swifty Codes
  • 992
  • 10
  • 23
3

Simple Solution in my case:

Product -> Clean

and then:

Product -> Run
Mick
  • 30,759
  • 16
  • 111
  • 130
2

I faced this error when I opened .xcodeproj instead of .xcworkspace while using cocoapods dependency manager.

Make sure you are opening .xcworkspace. enter image description here

Illegal Argument
  • 10,090
  • 2
  • 44
  • 61
2

I had the same error, and after digging through the logs I found the error "Duplicate Symbol"...

After a heap of searching I found that I had #imported a ".m" file instead of a ".h"

Maybe this might help someone.

BobCowe
  • 147
  • 3
  • 7
  • Where did you import .m file? – SatelBill Sep 06 '21 at 09:48
  • In one of my .m files I was supposed to import a .h file, but, by mistake, I accidentally imported a .m file. When I fixed it to import the .h file, the problem was solved. – BobCowe Sep 10 '21 at 22:28
1

In my case,

I faced the same clang error when I opened myproject.xcodeproj file instead of myproject.xcworkspace by mistake after installing cocoapods to my project.

iRiziya
  • 3,235
  • 1
  • 22
  • 36
0

it can be anything in your code, for me it was a problem with coredata classes?:

@objc(Attribute) // the problem
class Category : NSManagedObject{
}

changed to

@objc(Category)
class Category : NSManagedObject{
}
Ashkan Ghodrat
  • 3,162
  • 2
  • 32
  • 36
0

Set Host Application to your Project Target. Also, check the Allow testing Host Application APIs is turned on.

enter image description here

tania_S
  • 1,350
  • 14
  • 23
0

You might have to link file recently added. In My case files were not added but it got referenced in the project. The referenced file name must be appearing in red color. first, delete the referenced file, then you can right-click on the group add the file manually.