Reputation: 1976
I am trying to cross compile simple helloworld.c to run on ARM (Cortex-A5)
I get the following error
gcc: error trying to exec 'cc1' execvp: No such file or directory
HW/SW: SAMA5D31 processor, Android Linux
Host: Ubuntu 12.04
Makefile
CC=/home/userid/android4sam_v4.0/cross_compile_mentor/arm-2013.05/bin/arm-none-linux-gnueabi-gcc
CFLAG=I.
helloworld:helloworld.o
$(CC)-o helloworld helloworld.o -I.
I have compile the program on the host machine and works fine. Then I exported the cross compiler path and tried to compile
cross compiler path is
/home/userid/android4sam_v4.0/cross_compiler_mentor/arm-2013.05/arm-none-linux-gnueabi/bin
Also read a few post pointing to GCC_EXEC_PREFIX (env). When I echo $GCC_EXEC_PREFIX, I don't get anything back. If this is the cause can someone suggest how to address the issue.
Also I have read about defining -mcpu=cortex-A5. Is this necessary?
Also I did a locate cc1 found the following
/usr/lib/gcc/arm-linux-gnueabi/4.4.7/cc1
/usr/lib/gcc/arm-linux-gnueabi/4.6/cc1
I also have looked at Environment Variables Affecting GCC
I also read something about "xgcc -B " I am not sure if this is relevant to addressing the issue.
Output from gcc -print-search-dirs
install: /usr/lib/gcc/x86_64-linux-gnu/4.6/
programs: =/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux- gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../x86_64-linux-gnu/bin/
libraries: =/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../x86_64-linux-gnu/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/:/lib/x86_64-linux-gnu/4.6/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/4.6/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../x86_64-linux-gnu/lib/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../:/lib/:/usr/lib/
Also following command compiled without any issues
arm-linux-gnueabi-gcc -o serial -static serial.c
Update 12/1/2013 The following issue was resolved by modifying the CC variable as Chris Stratton suggest
gcc: error trying to exec 'cc1' execvp: No such file or directory
Upvotes: 3
Views: 6765
Reputation: 102205
Since you are using Android, you would use the toolchain provided by AOSP in the NDK.
When using the Android NDK, you usually only need the minimum API that introduced the architecture/platform. For ARM, I believe that's android-3
. You can use a later API, like android-21
.
Below is from my MacBook. The NDK is r10d, and its installed in /opt/android-ndk-r10d/
.
export PATH="/opt/android-ndk-r10d/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin:$PATH"
export CPP="arm-linux-androideabi-cpp"
export CC="arm-linux-androideabi-gcc"
export LD="arm-linux-androideabi-ld"
export AR="arm-linux-androideabi-ar"
export RANLIB="arm-linux-androideabi-ranlib"
export CFLAGS="-g3 -Os -mfloat-abi=softfp -mfpu=vfpv3-d16 --sysroot=/opt/android-ndk-r10d/platforms/android-21/arch-arm"
You definitely want to use --sysroot
so the system knows which headers and libraries to use. Your other option is to cobble it together with -I
, -L
and -l
.
Then:
$(CC) $(CFLAGS) -I. helloworld.c -o helloworld.exe
After that, you use adb
to push it to a device and execute it. Something like:
$ adb push helloworld.exe /data/local/tmp
$ adb shell
$ shell@android:/ $ cd /data/local/tmp
$ shell@android:/data/local/tmp $ ./helloworld.exe
Here are some additional CFLAGS
you should be aware of (from personal notes in a script to set up the environment):
# armeabi-v7a must use:
# CXXFLAGS += -march=armv7-a -mfloat-abi=softfp
# armeabi-v7a with Neon must use:
# CXXFLAGS += -march=armv7-a -mfloat-abi=softfp -mfpu=neon
# ARMv7 needs nothing special. In fact, specifying
# CXXFLAGS += -march=armv7 will result in a compile error.
# Cortex A8 requires a bug fix:
# LDFLAGS += --fix-cortex-a8
And related, here are the Cortex-A processor flags recommended by ARM Inc. Don't worry about the multilibs since Android takes care of that for you.
--------------------------------------------------------------------
| ARM Core | Command Line Options | multilib |
|----------|--------------------------------------------|----------|
|Cortex-A* | [-mthumb] -march=armv7-a | armv7-ar |
|(No FP) | | /thumb |
|----------|--------------------------------------------|----------|
|Cortex-A* | [-mthumb] -march=armv7-a -mfloat-abi=softfp| armv7-ar |
|(Soft FP) | -mfpu=vfpv3-d16 | /thumb |
| | | /softfp |
|----------|--------------------------------------------|----------|
|Cortex-A* | [-mthumb] -march=armv7-a -mfloat-abi=hard | armv7-ar |
|(Hard FP) | -mfpu=vfpv3-d16 | /thumb |
| | | /fpu |
--------------------------------------------------------------------
Upvotes: 1