1

I am trying to compile Sofia-SIP library for iOS for architectures armv6 and armv7 but I am running into problems. Below is what I am doing.

export DEVROOT=/Applications/Xcode_4_6.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer    
export SDKROOT=$DEVROOT/SDKs/iPhoneOS6.1.sdk    
export CC=$SDKROOT/usr/bin/llvm-gcc-4.2    
export CFLAGS="-pipe -no-cpp-precomp -isysroot $SDKROOT -arch armv7"    
export LDFLAGS="-syslibroot $SDKROOT -arch armv7"    
export CPP=$SDKROOT/usr/bin/llvm-g++-4.2./configure --host=arm-apple-darwin10    
sudo ./configure --host=arm-apple-darwin10

RESULT

Password:    
configure: WARNING: if you wanted to set the --build type, don't use --host.
    If a cross compiler is detected then cross compile mode will be used    
checking build system type... x86_64-apple-darwin12.5.0    
checking host system type... arm-apple-darwin10    
checking target system type... arm-apple-darwin10    
checking cached information... ok    
checking for a BSD-compatible install... /usr/bin/install -c    
checking whether build environment is sane... yes    
checking for gawk... gawk    
checking whether make sets $(MAKE)... yes    
checking for arm-apple-darwin10-strip... no    
checking for strip... strip    
checking whether to enable maintainer-specific portions of Makefiles... no    
checking for style of include used by make... GNU    
checking for arm-apple-darwin10-gcc... no    
checking for gcc... gcc    
checking for arm-apple-darwin10-gcc... gcc    
checking whether the C compiler works... yes

PROBLEM

I want the script to use llvm-gcc compiler. But instead it is looking for arm-apple-darwin10-gcc which it could not find and then finally ends up using gcc compiler.

Misha Brukman
  • 12,938
  • 4
  • 61
  • 78
Nir
  • 399
  • 3
  • 22

2 Answers2

3

I fought with this for a weekend, won the battle (with a lot of help), and have the following to return to the community:

  1. 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…

  1. …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".

Community
  • 1
  • 1
Florin Odagiu
  • 456
  • 6
  • 16
  • Thanks for sharing this answer. This was a very old question and after lot of try i gave up on this. After looking to your answer, i think i will have to again try this. – Nir Oct 21 '15 at 09:29
  • Hi Florin Odagiu. I'm very glad our work at https://github.com/RestComm/restcomm-ios-sdk is helpful to the community :). May I ask if you are still involved in Sofia SIP for iOS and what you are using it for? Sofia SIP presented a lot of challenges (and still does :() in the iOS integration and we 're always looking for people to share our experiences with and help each other. – atsakiridis May 18 '16 at 08:22
  • Thanks for the Sofia related insights. At the time I was involved in a "soft phone" project. I discovered the webRTC movement and built the app on top. Needed Sofia for signalling. I had a difficult employer and the relation with them was strained. When I had webRTC and Sofia playing nice together I presented a demo. They were seriously unimpressed, I left the company. Unfortunately I can't contribute anything else to the Sofia pool of knowledge. The lessons learned are in my long post. I guess it's pretty useless knowledge for you; useful only for novices - me, half a year ago. – Florin Odagiu May 31 '16 at 14:18
  • @Florin please guide me how to compile Sofia sip library ,actually I compiled but IPv6 getting DNS 503 error, but IPv4 working fine ,is there any changes required in sres.c file – raj yadav Sep 06 '17 at 05:21
2

Note that llvm-gcc is deprecated; you should be using clang instead:

% ls -l /usr/bin/llvm-gcc
lrwxr-xr-x  1 root  wheel  5 Nov  8  2013 /usr/bin/llvm-gcc@ -> clang

The following seems to work for me:

export DEVROOT="$(xcrun --sdk iphoneos --show-sdk-platform-path)/Developer"
export SDKROOT="$(xcrun --sdk iphoneos --show-sdk-path)"

export CC="/usr/bin/clang"
export CXX="/usr/bin/clang++"

export LD="${DEVROOT}/usr/bin/ld"
export AR="${DEVROOT}/usr/bin/ar"
export AS="${DEVROOT}/usr/bin/as"
export NM="${DEVROOT}/usr/bin/nm"
export RANLIB="${DEVROOT}/usr/bin/ranlib"
export LDFLAGS="-L${SDKROOT}/usr/lib/"

export ARM_ARCH="armv7"  # or "armv6" and adjust the --host=[...] flag below
export CFLAGS="-arch ${ARM_ARCH} -pipe -no-cpp-precomp -isysroot ${SDKROOT} -I${SDKROOT}/usr/include/"

export CPPFLAGS="${CFLAGS}"
export CXXFLAGS="${CFLAGS}"

Configure:

./configure --host=armv7-apple-darwin

Build:

make

Verify:

file `find . -name \*dylib`

Output:

./libsofia-sip-ua/.libs/libsofia-sip-ua.0.dylib:                                                       Mach-O dynamically linked shared library arm
./libsofia-sip-ua/.libs/libsofia-sip-ua.0.dylib.dSYM/Contents/Resources/DWARF/libsofia-sip-ua.0.dylib: Mach-O dSYM companion file arm
./libsofia-sip-ua/.libs/libsofia-sip-ua.dylib:                                                         Mach-O dynamically linked shared library arm

Credits:

Notes:

  • I dropped the -miphoneos-version-min=[...] flag from the other question as I did not think it was relevant to your question; up to you if you want to add it back into CFLAGS.
Community
  • 1
  • 1
Misha Brukman
  • 12,938
  • 4
  • 61
  • 78
  • This works partially for me. Now I am getting some error related to SystemConfiguration framework. "error: 'SCDynamicStoreCreate' is unavailable: not available on iOS" I am trying to resolve this. Let me know if you faced similar issue. – Nir May 26 '14 at 16:58
  • What version of OS X and Xcode are you using? What specific error are you getting? – Misha Brukman May 26 '14 at 17:44
  • Mac OS X 10.8.5 and Xcode 5.1.1 I am getting below error su_os_nw.c:170:11: error: 'SCDynamicStoreCreate' is unavailable: not available on iOS ref = SCDynamicStoreCreate( NULL, ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStore.h:146:1: note: function has been explicitly marked unavailable here SCDynamicStoreCreate ( ^ – Nir May 26 '14 at 18:05
  • I'm using OS X 10.9.3 and Xcode 5.1 and this works for me (one option: consider downgrading Xcode to 5.1 and see if it works?). Also, if you look at the source the error refers to, it has the annotation `__OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_NA);` which suggests it's an API that's not available on the iPhone. Answers to [another question](http://stackoverflow.com/q/23127996/3618671) suggest that you can modify such declarations to allow you to compile, but you may not be able to deploy to the App Store due to the usage of a private API. – Misha Brukman May 26 '14 at 19:06
  • Ok will try first option. But seems chances are too low. Thanks for your help. – Nir May 27 '14 at 05:12
  • I formatted one partition and installed OS X 10.9.3 and Xcode 5.1. But still I am stuck at same error. Any other suggestions? Do I need to setup any other path or any other flag? – Nir May 30 '14 at 11:06
  • This may involve (much) more work, but if you're really intent on building this library as part of some larger project, you will probably create an Xcode project for it, so maybe consider importing it into an Xcode project and let Xcode build it, rather than using the Makefiles in Sofia SIP? This would probably involve something like running `configure` to generate some headers and then importing the resulting tree into Xcode, and I'm not sure if this will fix your problem or if it's worthwhile to do, but just a thought as I am running out of ideas at this point. – Misha Brukman May 30 '14 at 16:52
  • Ok. Thanks for your inputs and time. – Nir Jun 03 '14 at 06:08
  • What next we need to do after compilation to include this libraries in xcode project ? please help me out ! – Devang Goswami Oct 18 '14 at 04:33
  • @DevGoswami please start a separate question thread about this, as that's a different conversation from this question, and likely other folks will be able to help you with it as well. Please post your inputs, what you've tried so far, error messages that you see, etc. – Misha Brukman Oct 20 '14 at 06:14
  • http://stackoverflow.com/questions/26466168/compile-sofia-library-for-ios-in-xcode – Devang Goswami Oct 21 '14 at 06:40