Page 1 of 1

ARM Cross-Compiling in C

Posted: Sat Jun 11, 2011 1:13 pm
by VoidElite
Hey guys. Trying to get a simple Hello World application to compile on:
*i386
*ppc
*armv6

I'm using this Makefile:

Code: Select all

I386_GCC=/Developer/usr/llvm-gcc-4.2/bin/i686-apple-darwin10-llvm-gcc-4.2
PPC_GCC=/Developer/usr/llvm-gcc-4.2/bin/powerpc-apple-darwin10-llvm-gcc-4.2
ARM_GCC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/llvm-gcc-4.2/bin/arm-apple-darwin10-llvm-gcc-4.2
APP=iOS_Test

Main: Main.o
	$(I386_GCC) -o bin//$(APP) obj/i386/*.c
	$(PPC_GCC) -o bin/ppc/$(APP) obj/ppc/*.c
	$(ARM_GCC) -o bin/armv6/$(APP) obj/armv6/*.c
	
Main.o:
	$(I386_GCC) -o obj/i386/$(APP).o src/*.c
	$(PPC_GCC) -o obj/ppc/$(APP).o src/*.c
	$(ARM_GCC) -o obj/armv6/$(APP).o src/*.c
When compiling Main.c into Main.o and then linking Main.o into iOS_Test for the ARM architecture it fails with these errors:
Last login: Sat Jun 11 18:58:24 on ttys000
Marc-A-Reeds-MacBook-Pro:~ MarcAReed$ cd iOS_Test
Marc-A-Reeds-MacBook-Pro:iOS_Test MarcAReed$ make
/Developer/usr/llvm-gcc-4.2/bin/i686-apple-darwin10-llvm-gcc-4.2 -o obj/i386/iOS_Test.o src/*.c
/Developer/usr/llvm-gcc-4.2/bin/powerpc-apple-darwin10-llvm-gcc-4.2 -o obj/ppc/iOS_Test.o src/*.c
/Developer/Platforms/iPhoneOS.platform/Developer/usr/llvm-gcc-4.2/bin/arm-apple-darwin10-llvm-gcc-4.2 -o obj/armv6/iOS_Test.o src/*.c
In file included from /usr/include/sys/_types.h:33,
from /usr/include/_types.h:27,
from /usr/include/stdio.h:64,
from src/Main.c:1:
/usr/include/machine/_types.h:36:24: error: arm/_types.h: No such file or directory
In file included from /usr/include/_types.h:27,
from /usr/include/stdio.h:64,
from src/Main.c:1:
/usr/include/sys/_types.h:94: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_blkcnt_t’
/usr/include/sys/_types.h:95: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_blksize_t’
/usr/include/sys/_types.h:96: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_dev_t’
/usr/include/sys/_types.h:99: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_gid_t’
/usr/include/sys/_types.h:100: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_id_t’
/usr/include/sys/_types.h:101: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_ino64_t’
/usr/include/sys/_types.h:103: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_ino_t’
/usr/include/sys/_types.h:107: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_mach_port_name_t’
/usr/include/sys/_types.h:108: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_mach_port_t’
/usr/include/sys/_types.h:109: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_mode_t’
/usr/include/sys/_types.h:110: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_off_t’
/usr/include/sys/_types.h:111: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_pid_t’
/usr/include/sys/_types.h:131: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_sigset_t’
/usr/include/sys/_types.h:132: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_suseconds_t’
/usr/include/sys/_types.h:133: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_uid_t’
/usr/include/sys/_types.h:134: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_useconds_t’
In file included from src/Main.c:1:
/usr/include/stdio.h:70: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘va_list’
/usr/include/stdio.h:75: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘off_t’
/usr/include/stdio.h:80: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘size_t’
/usr/include/stdio.h:87: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fpos_t’
/usr/include/stdio.h:145: error: expected specifier-qualifier-list before ‘fpos_t’
/usr/include/stdio.h:255: error: expected declaration specifiers or ‘...’ before ‘fpos_t’
/usr/include/stdio.h:265: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fread’
/usr/include/stdio.h:270: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/stdio.h:272: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fwrite’
/usr/include/stdio.h:290: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdio.h:296: error: expected declaration specifiers or ‘...’ before ‘va_list’
/usr/include/stdio.h:297: error: expected declaration specifiers or ‘...’ before ‘va_list’
/usr/include/stdio.h:298: error: expected declaration specifiers or ‘...’ before ‘va_list’
/usr/include/stdio.h:301: error: expected declaration specifiers or ‘...’ before ‘va_list’
/usr/include/stdio.h:322: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdio.h:331: error: expected declaration specifiers or ‘...’ before ‘off_t’
/usr/include/stdio.h:332: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ftello’
/usr/include/stdio.h:353: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdio.h:355: error: expected declaration specifiers or ‘...’ before ‘va_list’
/usr/include/stdio.h:356: error: expected declaration specifiers or ‘...’ before ‘va_list’
/usr/include/stdio.h:357: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdio.h:357: error: expected declaration specifiers or ‘...’ before ‘va_list’
/usr/include/stdio.h:358: error: expected declaration specifiers or ‘...’ before ‘va_list’
/usr/include/stdio.h:372: error: expected declaration specifiers or ‘...’ before ‘fpos_t’
/usr/include/stdio.h:385: error: expected declaration specifiers or ‘...’ before ‘va_list’
In file included from /usr/include/stdio.h:443,
from src/Main.c:1:
/usr/include/secure/_stdio.h:42: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/secure/_stdio.h:49: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/secure/_stdio.h:49: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/secure/_stdio.h:56: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/secure/_stdio.h:57: error: expected declaration specifiers or ‘...’ before ‘va_list’
/usr/include/secure/_stdio.h:63: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/secure/_stdio.h:63: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/secure/_stdio.h:64: error: expected declaration specifiers or ‘...’ before ‘va_list’
make: *** [Main.o] Error 1
Marc-A-Reeds-MacBook-Pro:iOS_Test MarcAReed$ 1
Seems to be compatibility issues between stdio.h and the ARM architecture.

Any ideas how to fix this?

EDIT: I think stdio.h can't be compiled for the ARM architecture if so how do I over come this obstacle?

Re: ARM Cross-Compiling in C

Posted: Sat Jun 11, 2011 7:41 pm
by Falco Girgis
Nah, you can definitely use stdio.h on ARM... and pretty much any architecture supports it.

It's pretty apparent that GCC just can't find the particular includes for ARM types which are required by stdio.h. With a bit of researching, these flags may help:

Code: Select all

-arch armv7 and -isysroot 
Although I must be honest, all of that iPhone shit is really DESIGNED to be compiled through XCode. You'll run into all sorts of obscure issues like this with a makefile.

Re: ARM Cross-Compiling in C

Posted: Sun Jun 12, 2011 4:07 am
by VoidElite
GyroVorbis wrote:Nah, you can definitely use stdio.h on ARM... and pretty much any architecture supports it.

It's pretty apparent that GCC just can't find the particular includes for ARM types which are required by stdio.h. With a bit of researching, these flags may help:

Code: Select all

-arch armv7 and -isysroot 
Although I must be honest, all of that iPhone shit is really DESIGNED to be compiled through XCode. You'll run into all sorts of obscure issues like this with a makefile.
I think that should be '-arch armv6' because that's what the compiler was for. But due to the fact that I'm directly invoking the ARM GCC compiler instead of GCC it does not allow me to use the arch flag. Maybe I should just use GCC? But when I use raw GCC it finds the PPC shit and i386 shit but not the ARM compiler.

Should I invoke the GCC(NA(COMPILER MOANS WHEN I PASS -ARCH ARMV6 TO GCC)) compiler or the ARM GCC(/Developer/Platforms/iPhoneOS.platform/Developer/usr/llvm-gcc-4.2/bin/arm-apple-darwin10-llvm-gcc-4.2) compiler?

EDIT: This is what happens when I try to run GCC with 'arch -armv6' or 'armv7':
gcc-4.2: error trying to exec '/usr/bin/arm-apple-darwin10-gcc-4.2.1': execvp: No such file or directory
Also when I add '-isysroot' it complains about it missing a parameter.
EDIT2: I've found some information mentioning something about passing '$SDKROOT' or something to the '-isysroot' but I believe this was Xcode-side. I have reason to believe I need to find the value of this 'SDKROOT' which I believe now is known as 'SDK_DIR' in later versions of the iOS SDK.

NOTE: I've got the iOS SDK installed ext.

Re: ARM Cross-Compiling in C

Posted: Sun Jun 12, 2011 11:23 am
by avansc

Re: ARM Cross-Compiling in C

Posted: Sun Jun 12, 2011 3:27 pm
by VoidElite
Would I be right in thinking that I should use '-I' and '-L' to explicitly define the location of the headers and libs for the Darwin ARM GCC compiler?

Re: ARM Cross-Compiling in C

Posted: Sun Jun 12, 2011 10:28 pm
by LeonBlade
VoidElite wrote:Would I be right in thinking that I should use '-I' and '-L' to explicitly define the location of the headers and libs for the Darwin ARM GCC compiler?
-l is for library name, -L is for library path. (sorry for this post I was a bit tired when I posted it and didn't really read I meant that -l and -L isn't for header files)

Re: ARM Cross-Compiling in C

Posted: Sun Jun 12, 2011 10:35 pm
by Falco Girgis
VoidElite wrote:Would I be right in thinking that I should use '-I' and '-L' to explicitly define the location of the headers and libs for the Darwin ARM GCC compiler?
Yes, most likely. If I were you, I would look to see what arguments XCode is giving GCC when compiling an iOS project through XCode.

Re: ARM Cross-Compiling in C

Posted: Mon Jun 13, 2011 9:28 am
by VoidElite
GyroVorbis wrote:
VoidElite wrote:Would I be right in thinking that I should use '-I' and '-L' to explicitly define the location of the headers and libs for the Darwin ARM GCC compiler?
Yes, most likely. If I were you, I would look to see what arguments XCode is giving GCC when compiling an iOS project through XCode.
Well you see, that's the hard part. I barely know how to use Xcode for anything but basic things. Also Apple are no help as they keep details like that retained most of the time. :3

Re: ARM Cross-Compiling in C

Posted: Mon Jun 13, 2011 11:57 am
by avansc
VoidElite wrote:
GyroVorbis wrote:
VoidElite wrote:Would I be right in thinking that I should use '-I' and '-L' to explicitly define the location of the headers and libs for the Darwin ARM GCC compiler?
Yes, most likely. If I were you, I would look to see what arguments XCode is giving GCC when compiling an iOS project through XCode.
Well you see, that's the hard part. I barely know how to use Xcode for anything but basic things. Also Apple are no help as they keep details like that retained most of the time. :3
Gyro is right, and xcode does not "hide" this.
here is just an example of one of my own projects.

Image

Re: ARM Cross-Compiling in C

Posted: Mon Jun 13, 2011 5:51 pm
by Falco Girgis
VoidElite wrote:
GyroVorbis wrote:
VoidElite wrote:Would I be right in thinking that I should use '-I' and '-L' to explicitly define the location of the headers and libs for the Darwin ARM GCC compiler?
Yes, most likely. If I were you, I would look to see what arguments XCode is giving GCC when compiling an iOS project through XCode.
Well you see, that's the hard part. I barely know how to use Xcode for anything but basic things. Also Apple are no help as they keep details like that retained most of the time. :3
Actually, no. Avansc is right. Usually everything I hate about XCode is that it keeps NOTHING hidden from you.