I fought with this for a weekend, won the battle (with a lot of help), and have the following to return to the community:
Regarding su_os_nw.c and the
SCDynamicStore: function has been explicitly marked unavailable for iOS
issue:
I was about to give up, but noticed that a fellow named Antonis Tsakirids from Restcomm reported success in integrating Sofia in their iOS SDK.
I then went to their git repository and had a look at their SDK.
In /dependencies/sofia-sip/libsofia-sip-ua/su/ I found the culprit: su_os_nw.c
They elegantly updated
#if defined (__APPLE_CC__)
to
#if defined (__APPLE_CC__) && !defined(TARGET_OS_IPHONE)
This solves it…
- …but it does not solve it just by itself…because apparently since Xcode 7, Apple did some toolchain utilities shuffling.
Stuff is not located in “usual” locations anylonger, and MishaBruckman’s $DEVROOT got obsolete.
For instance , I got errors about “ar” not being found.
export DEVROOT="$(xcrun --sdk iphoneos --show-sdk-platform-path)/Developer”
maps to /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
However, the toolchain utilities (ld, ar, as, nm, ranlib, along with the almighty clang) have been moved to /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin.
I bolded the part that should map to the new $DEVROOT.
Hope this helps someone save 2 weekend days of their life...
…and in the end, the 2 points expressed above were not enough to get out of the woods…Compilation did finish OK and I left it at that initially.
However, today I wanted to actually use the library. Created a new project, imported the library, hit Build and…more suffering…
libsofia-sip-ua.a does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target for architecture armv7.
At first I went “say wha’…?”
what’s this mumbo_jumbo about setting stuff in Xcode? I did things the old_school way, compiling in command line…
what do you mean “obtain an updated library from the vendor”…the “vendor” is me, I’m building the library…
what is this strange bitcode thing, anyway?
After doing my homework regarding bitcode I started wondering what hides behind Xcode’s ENABLE_BITCODE… Turns out it “means” passing the “-fembed-bitcode” flag to clang.
In conclusion, the line
export CFLAGS="-arch ${ARM_ARCH} -mios-version-min=7 -pipe -no-cpp-precomp -isysroot ${SDKROOT} -I${SDKROOT}/usr/include/"
became
export CFLAGS="-arch ${ARM_ARCH} -mios-version-min=7 -fembed-bitcode -pipe -no-cpp-precomp -isysroot ${SDKROOT} -I${SDKROOT}/usr/include/"
Rebuilt Sofia with the new settings, but then it started complaining that even though the main project itself is going ok, it's SUB-LIBRARIES (for example libstun.a) are not compiled with bitcode. A "make clean" got rid of the old garbage and compilation finished ok. Imported the newly produced lib into my Xcode project and everything was ok as well.
And that finally concludes it. Build successful for a project under Xcode 7 / iOS9 integrating Sofia library, in anno domini 2015…
...aaaand...I was still not out of the woods...
As soon I decided to add arm64 architecture to my project, Xcode started again to complain about Sofia:
ignoring file libsofia-sip-ua.a, file was built for archive which is not the architecture being linked (arm64)
Undefined symbols for architecture arm64
Pretty simple, I thought: I'll just replace armv7 with arm64:
export ARM_ARCH="arm64”
After that modification, disaster struck while ./configure-ing:
checking for gcc... /usr/bin/clang
checking for gcc... (cached) /usr/bin/clang
checking whether the C compiler works... no
configure: error: in `/work/fromSourceforge/sofia-sip-1.12.11':
configure: error: C compiler cannot create executables
See `config.log' for more details
The next day was spent figuring out what was wrong (I could not ./configure anylonger, even reverting back to armv7)
stormed stack overflow; no solution helped
checked ad re-checked every path on the system...I was surprised to find out that one can find clang and gcc in 3-4 places throughout macosx, but I digress...
trying to reinstall Xcode Developer Tools
ended up reinstalling Xcode itself...
...nothing helped.
An eagle-eyed colleague spotted what was wrong:
export ARM_ARCH="arm64”
The last quote sign was not "the same" as the first quote sign. The first quote sign is "the correct kind of quote sign".
Even if I didn't touch the second one with my own hand, TextEdit changed it all by itself while I was converting v7 to 64. Apparently it's "a feature", called SmartQuotes. I could not disable it, by the way.
Mental note: NEVER EVER use TextEdit again to edit the .bash_profile file.
Finally, I found myself in the posession of the 64 bit version of Sofia. Plugged it into my Xcode project, aaaaaaand....
ignoring file libsofia-sip-ua.a, file was built for archive which is not the architecture being linked (armv7)
Undefined symbols for architecture armv7
Hmmm...if I build it for 32 bits, it complains about 64 missing...If I build it for 64 bits, it complains about 32 missing...
Turns out there's a way to fuse together multiple libraries into a single "fat" one.
The utility is called lipo and you use it something like this:
lipo -create "path_to_lib_1" "path_to_lib2" -output "path_to_desired_name_of_the_merged_library"
So: SIP-ing along with Sofia, under iOS, as a single library that does both 32 and 64 bits...
Heewhhh...
.....aaaaaaaaand we're still not done...!
Problem: trying to do anything (REGISTER, for instance) promptly resulted in a 503 DNS Error
Cause : Sofia searches for the name servers list in etc/resolv.conf
Obviously, this being iOS, it either does not exist, OR it's outside of the app sandbox.
Solution : it's the second time when this guy, Antonis Tsakiridis, saves my ass. Respectful bow.
First, he talks about what he intends to do.
Second, he shows what he has actually done.
However, the solution exposes a new...
Problem: _res_9_init - undefined symbol for architecture (armv7 or arm64 here, depending on what I happened to have set for ARM_ARCH), while recompiling Sofia
Cause : I don't know. I can only infer from the solution, that the linker needed to be told about the "resolv" library
Solution : added -lresolv in two places:
- LDFLAGS (in the .bash_profile file)
- in the Xcode "application" project (the one that exercises the library); Targets ---> Linking ---> OtherLinkerFlags
Just like before, although the above solves what it was trying to solve, it also advances us to the next...
Problem: conditional execution of code under #IOS_BUILD (part of AT's solution at first problem) did not take place. Still getting 503 DNS Error...
Cause : I could not figure out for the life of me WHERE IT'S ACTUALLY DEFINED. Of course, defining it anywhere in my own code could have no effect, since Sofia is supposed to be an already compiled dependency; we don't get another chance at the preprocessor crunching through her code.
Solution: I replaced the IOS_BUID #define with an environment variable called IOS_BUILD that has the value...well...IOS_BUILD. I told Xcode about it (I'm trying to use not the word "define" to avoid confusion) at
Product ---> Scheme ---> EditScheme ---> Arguments ---> EnvironmentVariables.
In Sofia, I just substituted #Ifdef IOS_BUILD with calls to getenv() and strcmp().
After all that, behold...REGISTER takes place...
Also, DNS settings are correctly detected everytime I connect the iPhone to another wi-fi, thanks to Sofia's smart "resolver".