rukiman rukiman - 2 months ago 66
iOS Question

Mach-O Linker error, undefined symbols for architecture after upgrading xcode to 8.0

I have upgraded to

XCode 8.0
and it is giving me grief. The first issue was to do with code signing. Which I fixed by selecting a provisioning profile for debug and release from the General project settings. Weird not sure why it couldn't just work as it was compiling perfectly with the previous
XCode
. Previously
XCode
would say there is not provisional profile and prompt to fix it and would fix it. Seems a step back here. Anyways, went passed that issue.

The issue I have been facing all day is this error when I compile

Undefined symbols for architecture arm64:
"_write_ret", referenced from:
_dwsl in libtestlib.a(testlib.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


I searched for
write_ret
and it is only a prototype in a header file, this function isn't called anywhere at all!! (Background the static library is part of a bigger project I brought only the files/code I needed to compile the static library for iOS). This was compiling perfectly before for years. I went back to the static libary source code and to humour myself I deleted the
write_ret
prototype and compiled it and updated the library in the my project and rebuilt. Same error again!. What is going on here?? I confirmed it was definitely using the correct built library.

I then decided I'll just built for
armv7
only as this is an enterprise app. I went back to the static library project file and got rid of
armv7s
and
arm64
from "
valid architectures
". I change "architectures" to
armv7
. I rebuilt the library and updated the project with the new library.

I also went into the main project and change the valid architectures to build for only
armv7
.

This time when I built my project I get this error

ld: warning: ignoring file /Users/rrr/Library/Developer/Xcode/DerivedData/P-eaxegvaceikvgqgllfiardmoorbv/Build/Products/Debug-iphoneos/libtestlib.a,
file was built for archive which is not the architecture being linked (armv7):
/Users/rrr/Library/Developer/Xcode/DerivedData/P-eaxegvaceikvgqgllfiardmoorbv/Build/Products/Debug-iphoneos/libtestlib.a


In the terminal I ran lipo
libtestlib.a
-info I get this:

input file libtestlib.a is not a fat file
Non-fat file: libtestlib.a is architecture: armv7


So it is built for
armv7
, so what is
XCode
complaining about really?

I am out of ideas now. Can anyone shed some light here?

I would like to get it to work with all the architectures as it was doing before the
XCode
upgrade I did on Friday. But worst case atleast compile to work only for
armv7
. My understanding is that it will still run on anything iPhone 5s and newer anyway.

Answer

At first, As you already know, you should support arm64 in order to support 64 bit architecture following Apple's rule.

At second, let's talk about undefined symbol issue, your first question.
I am not sure exactly from your situation description but,
one thing to my mind reading the question is that your static library may depend on some dylib(dynamic or shared library) which is deprecated from Xcode 7.

The possible scenario is your dylib library was red-marked in the project from Xcode 8 update version because this was replaced with tbd instead of dylib.

So, this library is now missing status, and you did remove it in the library list and you forgot it.
That's why your _write_ret symbol in libtestlib.a cannot be linked for architecture arm64 anymore.(dylib is missing status.)

if this scenario is true, import tbd instead of dylib.(text-based stub libraries).


let's talk about your second question related to error log.

ld: warning: ignoring file /Users/rrr/Library/Developer/Xcode/DerivedData/P-       eaxegvaceikvgqgllfiardmoorbv/Build/Products/Debug-iphoneos/libtestlib.a, 
file was built for archive which is not the architecture being linked (armv7):
 /Users/rrr/Library/Developer/Xcode/DerivedData/P-    eaxegvaceikvgqgllfiardmoorbv/Build/Products/Debug-iphoneos/libtestlib.a 

This log can be about Build Active Architecture Only in Xcode build setting.
check 'Build Active Architecture Only' from Yes to No.
It error log could be generated when Build Active Architecture Only is set to YES in your build setting situation. and, if it does not work, Have you ever clean your DerivedData directory and project?

If you already tried, it could be possible that your static library is actually not in the /Users/rrr/Library/Developer/Xcode/DerivedData/P-eaxegvaceikvgqgllfiardmoorbv/Build/Products/Debug-iphoneos/libtestlib.a.

so, you can move your static library output into this project and try it again.

These are just scenario for your situation as I got your question. I wish it became a little help.

Thanks.

Comments