0Day Forums
Xcode build failure "Undefined symbols for architecture x86_64" - Printable Version

+- 0Day Forums (https://zeroday.vip)
+-- Forum: Coding (https://zeroday.vip/Forum-Coding)
+--- Forum: Objective-C (https://zeroday.vip/Forum-Objective-C)
+--- Thread: Xcode build failure "Undefined symbols for architecture x86_64" (/Thread-Xcode-build-failure-quot-Undefined-symbols-for-architecture-x86-64-quot)

Pages: 1 2 3


Xcode build failure "Undefined symbols for architecture x86_64" - handmaids61231 - 07-21-2023

An Xcode beginner's question:

It is my first experience with Xcode 4.6.3.

I am trying to write a very simple console program, that searches for paired BT devices and prints them to an NSLog.

It builds with the following error:

Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_IOBluetoothDevice", referenced from:
objc-class-ref in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I searched like crazy. The common problem should be a reference to a file, of which only the header files are imported and no implementation (*.m-file) is found by the linker. The IOBluetooth library is however, a standard Framework like the Foundation Framework.

What am I missing in my above statement?

I also have tried building it for a 32-bit machine (build fails again). It is clearly a linker error, however I have no idea, to what it relates, except that there is an issue with finding the implementation for IOBluetoothDevice, on both x86 and x64 architecture, while the header files are from a standard included Framework, called IOBluetooth?

For your information my main code "main.m" being:

#import <Foundation/Foundation.h>
#import <IOBluetooth/objc/IOBluetoothDevice.h> // Note the import for bluetooth
#import <IOBluetooth/objc/IOBluetoothDeviceInquiry.h> // Note the import for bluetooth


int main(int argc, const char * argv[])
{
@autoreleasepool {
IOBluetoothDevice *currentDevice;
NSArray *devices = [ IOBluetoothDevice pairedDevices];


for (id currentDevice in devices){
NSLog(@"%i : %@",[ currentDevice classOfDevice ], [ currentDevice name ]);
}
}
return 0;
}

Thanks for any help or pointers to the right direction.


RE: Xcode build failure "Undefined symbols for architecture x86_64" - thready56605 - 07-21-2023

When updating to Xcode 7.1, you might see this type of error, and it can't be resolved by any of the above answers. One of the symptoms in my case was that the app runs on the device not in the simulator. You'll probably see a huge number of errors related to pretty much all of the frameworks you're using.

The fix is actually quite simple. You just need to delete an entry from the "Framework Search Paths" setting, found in your TARGETS > Build Settings > Search Paths section (make sure the "All" tab is selected)

[![enter image description here][1]][1]

**If you see another entry here (besides $(inherited)) for your main target(s) or your test target, just delete the faulty path from all targets and rebuild.**


[1]:



RE: Xcode build failure "Undefined symbols for architecture x86_64" - unseemlily760091 - 07-21-2023


> Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_xxx",
> referenced from:
> objc-class-ref in yyy.o

This generally means, you are calling "xxx" (it may be a framework or class) from the class "yyy". The compiler can not locate the "xxx" so this error occurs.

You need to add the missing files(in this case "xxx") by right click on your project folder in navigator window and tap on "**Add files to "*YourProjectName*"**" option.

A popup window will open your project files in Finder. There, you can see the missing files and just add them to your project. Don't forget to check the "**Copy items if needed**" box. Good luck!!


RE: Xcode build failure "Undefined symbols for architecture x86_64" - gridded348855 - 07-21-2023

I have also seen this error on Xcode 7.2 when the derived data becomes corrupted (in my case I interrupted a build and suspect that was the root cause).

So if the other solutions (notably Chris's and BraveS's which I suspect are more likely) do not fit your problem try deleting derived data (Select: Window / Projects / Derived Data -> Delete) and re-building.

(Added for reference by others - I know the original question has been answered correctly).


RE: Xcode build failure "Undefined symbols for architecture x86_64" - deaden897765 - 07-21-2023

I had the same error, because instead of deleting a file I simply removed references to it. Locating the file in Finder and removing it helped.


RE: Xcode build failure "Undefined symbols for architecture x86_64" - ore969 - 07-21-2023

I have found this can also occur if you drag a folder with Objective-C files into your project. If that folder appears blue I think it indicates its not properly linked. You can verify this (if you use version control) because whenever you add new files the pbxproj file should update with links to those new files. However you may find that after you added a folder that the pbxproj file did not change (and hence there is a linking error). So you will get auto-complete working and it will find the classes you imported, but when it goes to actually build the image it fails with this error code.

The solution is to not add the folder but rather add the files. Do this and you should see the pbxproj file update and it should fix this error.

This also assumes you've done what was suggested above and have properly linked all the right frameworks.


RE: Xcode build failure "Undefined symbols for architecture x86_64" - snapback622 - 07-21-2023

In my Case , it was not a library, it was some classes ..

> Undefined symbols for architecture x86_64:
> "_OBJC_CLASS_$_ClassNmae", referenced from: objc-class-ref in
> SomeClassName" . . .
>
> d: symbol(s) not found for architecture x86_64
>
> clang: error: linker command failed with exit code 1 (use -v to see
> invocation)


**Solution**
I had several targets in Xcode with several schemas ( Production , Dev etc ) .. some of my newly added implementation ( Class.m ) were missing in

> Xcode->Targets->Build Phases->Compile Sources

So I had to add them manually.

then I could compile & build successfully.




RE: Xcode build failure "Undefined symbols for architecture x86_64" - updrink177958 - 07-21-2023

I tried just about everything here but my problem turned out to be the remnants of a previous cocoapods build. What worked for me was:

1. `rm -Rf Pods; pod install`
2. Delete Derived Data (Window/Projects... select your target. click Delete Button)
3. Rebuild




RE: Xcode build failure "Undefined symbols for architecture x86_64" - jarrettdmgjuzsh - 07-21-2023

If you're getting this error when trying to link to a C file, first double check the function names for typos. Next double check that you are not trying to call a C function from a C++ / Objective-C++ environment without using the `extern C {}` construct. I was tearing my hair out because I had a class that was in a .mm file which was trying to call C functions. It doesn't work because in C++, the symbols are mangled. You can actually see the concrete symbols generated using the nm tool. Terminal to the path of the .o files, and run `nm -g` on the file that is calling the symbol and the one that should have the symbol, and you should see if they match up or not, which can provide clues for the error.

nm -g file.o

You can inspect the C++ symbols demangled with this:

nm -gC file.o


RE: Xcode build failure "Undefined symbols for architecture x86_64" - fadeless405 - 07-21-2023

**UPD**

Apple **requires** to use **arm64** architecture. Do not use x32 libraries in your project

So the answer below is not correct anymore!

---


**Old answer**

The new Xcode 5.1 sets the architecture armv7,armv7s,and **arm64** as default.

And sometimes the error **"build failure “Undefined symbols for architecture x86_64”"** may be caused by this. Because, some libs (not Apple's) were compiled for x32 originally and doesn't support x64.

So what you need, is to change the "Architectures" for your project target like this

**NB.** If you're using Cocoapods - you should do the same for "Pods" target.


![enter image description here][1]



[1]: