Author Topic: Setting up a proper toolcahin  (Read 2766 times)

LeoTh3o

  • Full Member
  • ***
  • Posts: 230
  • Reputation: 43
    • ET&C
  • Computers: MacBook Pro 15', half 2009, OS X 10.8.1
  • iDevices: iPod 3G iOS 5.1.1; iPad 2 WiFi iOS 5.1.1 jb
Setting up a proper toolcahin
« on: February 04, 2012, 06:34:40 am »
Hello, I'm a bit surprised there's still nothing like this on the net (or I was't able to locate it, which happens, but not too often) but the point is: how to setup a proper toolchain (especially on the iDevice)? I've gone brought lots of guides, but I always ended up with errors of some sort when invoking gcc (let alone ./configure). I consider myself a modest-talented terminal ninja, but up here I hadn't luck. Could someone help?

Thanks a lot and sorry if this seems noob, but I always have had different errors each time I tried a version of iphone-gcc. I even try to build my own with no more luck.
0xEB        0xFE
jmp short -2

Trcx528

  • Haxor
  • Hero Member
  • *****
  • Posts: 4502
  • Reputation: 166
  • Google it!
    • iNinjas
  • Badges:
  • Computers: 13" 2011 Macbook Pro, 120 GB SSD and 16 GB of Ram
  • iDevices: None
Re: Setting up a proper toolcahin
« Reply #1 on: February 04, 2012, 08:02:21 am »
Hello and welcome, glad that you found us.  I do not know how useful mysql will be to you, the porter hasn't maintained it and it does not work with php (and idk why).  But as to your question, try reading https://ininjas.com/forum/index.php?topic=2536

LeoTh3o

  • Full Member
  • ***
  • Posts: 230
  • Reputation: 43
    • ET&C
  • Computers: MacBook Pro 15', half 2009, OS X 10.8.1
  • iDevices: iPod 3G iOS 5.1.1; iPad 2 WiFi iOS 5.1.1 jb
Re: Setting up a proper toolcahin
« Reply #2 on: February 04, 2012, 12:55:52 pm »
OK, in some of my previous installations I didn't use the installsdk3 as I wasn't said so, but now I did it. Yet I get "C compiler cannot create executables" when I try a configure for some software like git or svn, which really needs an update from the versions available in cydia.
Any suggestions?
0xEB        0xFE
jmp short -2

Trcx528

  • Haxor
  • Hero Member
  • *****
  • Posts: 4502
  • Reputation: 166
  • Google it!
    • iNinjas
  • Badges:
  • Computers: 13" 2011 Macbook Pro, 120 GB SSD and 16 GB of Ram
  • iDevices: None
Re: Setting up a proper toolcahin
« Reply #3 on: February 04, 2012, 04:01:41 pm »
Try reading the config.log probably about 1/2 way through there is the exact error message. If I had to guess I would say when it try's to run ggc output it gets a "Killed: 9" error that is caused by apple's code signing requirements. You have to use ldid to fake codesign the binaries. Idk how but some how I managed to get it to not require code signing on my device. No clue how I managed that because I'm on ios 5, which disables the commands to disable code signing that were present in ios 4. Others have specullated that I could use a script to take gcc's place and then run the real gcc and sign the executables. There is some untested code some where on this forum about how to do it with python. I'm sure there are other methods but most of the devs on here use one of the above methods.

LeoTh3o

  • Full Member
  • ***
  • Posts: 230
  • Reputation: 43
    • ET&C
  • Computers: MacBook Pro 15', half 2009, OS X 10.8.1
  • iDevices: iPod 3G iOS 5.1.1; iPad 2 WiFi iOS 5.1.1 jb
Re: Setting up a proper toolcahin
« Reply #4 on: February 05, 2012, 06:47:35 am »
Apparently this was the error.configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h.  */
| #include <stdio.h>
| int
| main ()
| {
| FILE *f = fopen ("conftest.out", "w");
|  return ferror (f) || fclose (f) != 0;
|
|   ;
|   return 0;
| }
configure:4676: error: C compiler cannot create executables
See `config.log' for more details.


Doing it manually I get this:
Unknown-iDevice:~ root# gcc -v test.c -o test
Using built-in specs.
Target: arm-apple-darwin9
Configured with: ../llvm-gcc-4.2/configure --build=x86_64-unknown-linux-gnu --host=arm-apple-darwin9 --enable-static=no --enable-shared=yes --prefix=/usr --localstatedir=/var/cache/iphone-gcc --enable-languages=c,c++,objc,obj-c++ --enable-wchar_t=no --with-gxx-include-dir=/usr/include/c++/4.0.0
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5555)
 /usr/libexec/gcc/arm-apple-darwin9/4.2.1/cc1 -quiet -v -D__DYNAMIC__ test.c -fPIC -fno-builtin-strcat -fno-builtin-strcpy -quiet -dumpbase test.c -maspen-version-min=2.0 -auxbase test -version -o /var/tmp//ccsGJdur.s
ignoring nonexistent directory "/usr/lib/gcc/arm-apple-darwin9/4.2.1/../../../../arm-apple-darwin9/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/gcc/arm-apple-darwin9/4.2.1/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
GNU C version 4.2.1 (Based on Apple Inc. build 5555) (arm-apple-darwin9)
   compiled by GNU C version 4.2.1 (Based on Apple Inc. build 5555).
GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=64382
Compiler executable checksum: 7f3b3f9f41787e32b9fcd64c73e06ffd
 as -arch arm -force_cpusubtype_ALL -o /var/tmp//ccJ5Vcea.o /var/tmp//ccsGJdur.s
 /usr/libexec/gcc/arm-apple-darwin9/4.2.1/collect2 -dynamic -arch arm -force_cpusubtype_ALL -aspen_version_min 2.0 -weak_reference_mismatches non-weak -o test -lcrt1.10.5.o -L/usr/lib/gcc/arm-apple-darwin9/4.2.1 -L/usr/lib/gcc/arm-apple-darwin9/4.2.1 -L/usr/lib/gcc/arm-apple-darwin9/4.2.1/../../.. /var/tmp//ccJ5Vcea.o -lgcc_s.10.5 -lgcc -lSystem
ld: library not found for -lSystem
collect2: ld returned 1 exit status



Should I consider building on my mac instead that on the iPad?
0xEB        0xFE
jmp short -2

Don't like seeing ads? Click here to register!

Trcx528

  • Haxor
  • Hero Member
  • *****
  • Posts: 4502
  • Reputation: 166
  • Google it!
    • iNinjas
  • Badges:
  • Computers: 13" 2011 Macbook Pro, 120 GB SSD and 16 GB of Ram
  • iDevices: None
Re: Setting up a proper toolcahin
« Reply #5 on: February 05, 2012, 10:24:17 am »
It's somewhat of a pain to set up a cross compiler.  If you ran the installsk3 command I would take a look in /var/sdk/usr/lib and look for a libsystem or something like that and symlink it /usr/lib and try again.  Otherwise generate a fake lib, because although some try to compile against certain libs they really aren't required.  You should check out my porting notes on the wiki, they are poorly organized an not well formatted but still may be useful. 

LeoTh3o

  • Full Member
  • ***
  • Posts: 230
  • Reputation: 43
    • ET&C
  • Computers: MacBook Pro 15', half 2009, OS X 10.8.1
  • iDevices: iPod 3G iOS 5.1.1; iPad 2 WiFi iOS 5.1.1 jb
Re: Setting up a proper toolcahin
« Reply #6 on: February 06, 2012, 02:49:36 pm »
Apparently libSystem.dylib wasn't copied in /usr/lib from the sdk directory, but I symlinked it and now all works with configure.

I have a rather unusual problem with make when libtool is invoked.
1) I don't get why libtool is called from /usr/build-1/libtool , but I just did ln -s $(which libtool) /usr/build-1/libtool
2) libtool is invoked without the --tag=CC flag and I hate to do it manually. I thought to puton that ridiculous path above a bash script that added the flag and redirected to the right libtool, but I can't find a way to use the argv. I'd be really pissed off if bash didn't allow argv/argc control and some solution I tried from the net don't seem to work, so I am adding the flag manually for each step. so I messed a bit with one .mk file and all went smooth again.
3) One of my attempts to port asked for libsqlite3.la, while the system can provide the dylib (which don't work symlinked). Rebuilding from scourcecode instead of using the Cydia lib solved the problem.
« Last Edit: February 07, 2012, 01:57:10 pm by LeoTh3o »
0xEB        0xFE
jmp short -2

Trcx528

  • Haxor
  • Hero Member
  • *****
  • Posts: 4502
  • Reputation: 166
  • Google it!
    • iNinjas
  • Badges:
  • Computers: 13" 2011 Macbook Pro, 120 GB SSD and 16 GB of Ram
  • iDevices: None
Re: Setting up a proper toolcahin
« Reply #7 on: February 06, 2012, 04:22:14 pm »
Try ./configure --help

Typically I can find a way of adding arguments in there and having it generate it for me, rather than having to do it manually. 

LeoTh3o

  • Full Member
  • ***
  • Posts: 230
  • Reputation: 43
    • ET&C
  • Computers: MacBook Pro 15', half 2009, OS X 10.8.1
  • iDevices: iPod 3G iOS 5.1.1; iPad 2 WiFi iOS 5.1.1 jb
Re: Setting up a proper toolcahin
« Reply #8 on: February 07, 2012, 02:08:15 pm »
I managed to end without errors, even if it took me a while to set the right flags with configure.
Now I'm blocked with a build of apache in which apparently there hasn't been any build errors, but httpd is killed by signal 12 "sys". I've tried to clear all and rebuild, but without better results. I have tried both ldid and ldone to fakesign, but neither worked.
I know there's lighted which just work fine, but I prefer apache to it for a more readable (at least for me) configuration file and more experience.
Again, suggestions are welcomed.
0xEB        0xFE
jmp short -2

Trcx528

  • Haxor
  • Hero Member
  • *****
  • Posts: 4502
  • Reputation: 166
  • Google it!
    • iNinjas
  • Badges:
  • Computers: 13" 2011 Macbook Pro, 120 GB SSD and 16 GB of Ram
  • iDevices: None
Re: Setting up a proper toolcahin
« Reply #9 on: February 07, 2012, 06:20:10 pm »
I have no clue, I have never seen that error before.  Some quick googling suggests that the sys error 12 is "Bad argument to routine (SVr4)," but I have no clue how to fix it. 

Personally I like lighttpd more as it is lighter weight, but to each his own. 

Don't like seeing ads? Click here to register!

LeoTh3o

  • Full Member
  • ***
  • Posts: 230
  • Reputation: 43
    • ET&C
  • Computers: MacBook Pro 15', half 2009, OS X 10.8.1
  • iDevices: iPod 3G iOS 5.1.1; iPad 2 WiFi iOS 5.1.1 jb
Re: Setting up a proper toolcahin
« Reply #10 on: February 10, 2012, 11:00:34 am »
I ended up realizing that that building httpd is way harder than it seems. I think this is partly due the dependencies (respectively apr and apr-util) are installed from cydia without much care, as the packages really miss a lot. Above all, apr should create /build-1 containing some useful files for higher level applications, yet this folder is missing. Unfortunately, trying to build on-the-go doesn't work with apr (as kqueue.c raises a lot of problems about poll_* functions missing operands. Usually this happened if I didn't had headers, but there isn't such error now and I fear a bit to just comment out the part that does not compile. Apr-util is, if possible, messier as it rely on that folder where apr should have left libtool and some .mk file to help configuration. It apparently could go until make is called, but then, when libtool calls ar, this last one receive wrong arguments (but then why libtool doesn't complain too?).
I tried crosscompiling on Mac, but the binaries I create seems to be x86_64 (from lipo) and arm (from configure). I can't force the C compiler as any respectable configure do tests and wants to run programs, which is not possible if they're ARM on Intel.

All the sites that I tried about crosscompiling for iphone from mac either are old (SDK 2.0) or/and doesn't work as cross-gcc fails building, let alonte compile.

These are the settings I used:
export CFLAGS="$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk"
export CPP="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/c++ $CPPFLAGS"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib -Wl,-dylib_install_name,@executable_path/$LIBNAME"
export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/"
#
# On apr-1.4.5
#
./configure LD=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ld --host=arm-apple-darwin --with-devrandom=/dev/random --enable-threads --prefix=/usr
make && make install DESTDIR=/tmp/crossbuild

but, as I said, there's already a problem here as built libs and binaries are x86_64 and not arm.


So I ask again how to setup a cross toolchain on Mac. Thanks in advance
0xEB        0xFE
jmp short -2

A3MIRAL

  • Leader
  • Hero Member
  • *****
  • Posts: 2899
  • Reputation: 105
  • A3MIRAL -- Reporting for Duty
    • A3MIRAL
  • Badges:
  • Computers: Dell XPS15 (6 GB ram, Core i7 @ 2.0 GHz, 750 GB HDD @ 7200 RPM)
  • iDevices: iPod touch 3G 32GB, iPhone 5 32GB
Re: Setting up a proper toolcahin
« Reply #11 on: February 10, 2012, 07:59:29 pm »
I have no clue, I have never seen that error before.  Some quick googling suggests that the sys error 12 is "Bad argument to routine (SVr4)," but I have no clue how to fix it. 

Personally I like lighttpd more as it is lighter weight, but to each his own.

I agree.
apache would probably slowly occupy all of your ram

Trcx528

  • Haxor
  • Hero Member
  • *****
  • Posts: 4502
  • Reputation: 166
  • Google it!
    • iNinjas
  • Badges:
  • Computers: 13" 2011 Macbook Pro, 120 GB SSD and 16 GB of Ram
  • iDevices: None
Re: Setting up a proper toolcahin
« Reply #12 on: February 11, 2012, 04:43:27 pm »
...I think this is partly due the dependencies (respectively apr and apr-util) are installed from cydia without much care...
You will find this a lot with cydia, the apt is about they only thing that actually works exactly as it should, everything else is a mess from a standards point of view, unfortunately it is most times less work to compile everything yourself than it is to depend on other stuff that has already been built. 

LeoTh3o

  • Full Member
  • ***
  • Posts: 230
  • Reputation: 43
    • ET&C
  • Computers: MacBook Pro 15', half 2009, OS X 10.8.1
  • iDevices: iPod 3G iOS 5.1.1; iPad 2 WiFi iOS 5.1.1 jb
Re: Setting up a proper toolcahin
« Reply #13 on: February 12, 2012, 05:39:04 am »
There's an absurdity about libevent (which includes kqueue.c) building without problems and apr blocking without include errors. I grabbed kqueue.c and its related files from libevent and replaced the default one in apr. Now i can build, but i fear crashes may occurr.
Update: as expected, using code from a different package just mess things up. Apr-util cannot properly reference to "custom" apr-kqueue functions and doesn't compile. Right now I have a hybrid between my (broken) version and the Cydia (useless to build) one and apr has built. Tests have gone well except the one about dbn-sqlite.
Apache configure doesn't stop anymore for a too-old version of apr-util, but hangs when it tries to enable mod_crypto_something as apr has evidently built without such support. Too tired right now to continue.
« Last Edit: February 12, 2012, 12:50:10 pm by LeoTh3o »
0xEB        0xFE
jmp short -2

LeoTh3o

  • Full Member
  • ***
  • Posts: 230
  • Reputation: 43
    • ET&C
  • Computers: MacBook Pro 15', half 2009, OS X 10.8.1
  • iDevices: iPod 3G iOS 5.1.1; iPad 2 WiFi iOS 5.1.1 jb
Re: Setting up a proper toolcahin
« Reply #14 on: February 14, 2012, 10:40:16 am »
Ah, I almost did building apr by disabling kqueue (which was the messy one) from configure, but Here's what I got when tested:

APR Lock Performance Test
==============

apr_thread_mutex_t Tests
    Initializing the apr_thread_mutex_t (UNNESTED)          OK
    Starting 1 threads    OK
microseconds: 255712 usec
apr_thread_mutex_t Tests
    Initializing the apr_thread_mutex_t (NESTED)            OK
    Starting 1 threads    OK
microseconds: 320128 usec
apr_thread_rwlock_t Tests
    Initializing the apr_thread_rwlock_t                    OK
    Starting 1 threads    OK
microseconds: 246152 usec
apr_thread_mutex_t Tests
    Initializing the apr_thread_mutex_t (UNNESTED)          OK
    Starting 2 threads    OK
microseconds: 58159854 usec
apr_thread_mutex_t Tests
    Initializing the apr_thread_mutex_t (NESTED)            OK
    Starting 2 threads    OK
microseconds: 70204337 usec
apr_thread_rwlock_t Tests
    Initializing the apr_thread_rwlock_t                    OK
    Starting 2 threads    OK
microseconds: 13199901 usec
apr_thread_mutex_t Tests
    Initializing the apr_thread_mutex_t (UNNESTED)          OK
    Starting 3 threads    OK
microseconds: 134282208 usec
apr_thread_mutex_t Tests
    Initializing the apr_thread_mutex_t (NESTED)            OK
    Starting 3 threads    OK
microseconds: 73839776 usec
apr_thread_rwlock_t Tests
    Initializing the apr_thread_rwlock_t                    OK
    Starting 3 threads    OK
microseconds: 63805713 usec
apr_thread_mutex_t Tests
    Initializing the apr_thread_mutex_t (UNNESTED)          OK
    Starting 4 threads    OK
microseconds: 39634098 usec
apr_thread_mutex_t Tests
    Initializing the apr_thread_mutex_t (NESTED)            OK
    Starting 4 threads    OK
microseconds: 40543928 usec
apr_thread_rwlock_t Tests
    Initializing the apr_thread_rwlock_t                    OK
    Starting 4 threads    OK
microseconds: 44098139 usec
apr_thread_mutex_t Tests
    Initializing the apr_thread_mutex_t (UNNESTED)          OK
    Starting 5 threads    OK
microseconds: 90165282 usec
apr_thread_mutex_t Tests
    Initializing the apr_thread_mutex_t (NESTED)            OK
    Starting 5 threads    OK
microseconds: 88474560 usec
apr_thread_rwlock_t Tests
    Initializing the apr_thread_rwlock_t                    OK
    Starting 5 threads    OK
microseconds: 96663233 usec
apr_thread_mutex_t Tests
    Initializing the apr_thread_mutex_t (UNNESTED)          OK
    Starting 6 threads    OK
microseconds: 143344295 usec
apr_thread_mutex_t Tests
    Initializing the apr_thread_mutex_t (NESTED)            OK
    Starting 6 threads    OK
microseconds: 109802007 usec
apr_thread_rwlock_t Tests
    Initializing the apr_thread_rwlock_t                    OK
    Starting 6 threads    OK
microseconds: 185951399 usec
Trying proc mutexes with mechanism `default'...
/bin/sh: line 2:  9971 Bad system call: 12     ./$prog
testatomic          : SUCCESS
testdir             : SUCCESS
testdso             : FAILED 8 of 9
testdup             : SUCCESS
testenv             : SUCCESS
testfile            : SUCCESS
testfilecopy        : SUCCESS
testfileinfo        : SUCCESS
testflock           : SUCCESS
testfmt             : SUCCESS
testfnmatch         : SUCCESS
testargs            : SUCCESS
testhash            : SUCCESS
testipsub           : SUCCESS
testlock            : SUCCESS
testcond            : SUCCESS
testlfs             : SUCCESS
testmmap            : SUCCESS
testnames           : SUCCESS
testoc              : SUCCESS
testpath            : SUCCESS
testpipe            : SUCCESS
testpoll            : SUCCESS
testpools           : SUCCESS
testproc            : SUCCESS
testprocmutex       : -/bin/sh: line 2:  9974 Bad system call: 12     ./$prog
Programs failed: testmutexscope testall
make[1]: *** [check] Error 140
make[1]: Leaving directory `/apr/test'
make: *** [check] Error 2


So the bad system call exist already at this level...
0xEB        0xFE
jmp short -2