'Error building Android kernel: "multiple target patterns"
I attempted to build a fresh kernel for Nexus 5X following Google's instructions on this page
- Build system: Ubuntu 14.04 x86_64
- Target system: MTC19T/bullhead (Actually any marshmallow version on 5X)
- Toolchain: android-6.0.1_r25/prebuilts/gcc/linux-x86/aarch64/
Exact sequence of commands I executed are:
$ git clone https://android.googlesource.com/kernel/msm
$ export ARCH=arm64
$ export CROSS_COMPILE=aarch64-linux-android-
$ cd msm
$ git checkout -b android-msm-bullhead-3.10-marshmallow-mr1 origin/android-msm-bullhead-3.10-marshmallow-mr1
$ make bullhead_defconfig
$ make
I am greeted with following error after last command:
Makefile:796: *** multiple target patterns. Stop.
Investigations:
Now line 796 in makefile is:
vmlinux: scripts/link-vmlinux.sh $(vmlinux-deps) FORCE
and other relevant lines are:
vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_INIT) $(KBUILD_VMLINUX_MAIN)
export KBUILD_VMLINUX_INIT := $(head-y) $(init-y)
export KBUILD_VMLINUX_MAIN := $(core-y) $(libs-y) $(drivers-y) $(net-y)
export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
I found that if I remove $(libs-y)
from $(KBUILD_VMLINUX_MAIN)
this error disappears, and build continues for some time. I am sure I wil find some or other issue later, so I decided to debug further.
Disclaimer: Rest of this is a bit gray area for me
$(libs-y)
is defined as:
libs-y := lib/
libs-y1 := $(patsubst %/, %/lib.a, $(libs-y))
libs-y2 := $(patsubst %/, %/built-in.o, $(libs-y))
libs-y := $(libs-y1) $(libs-y2)
So I called scripts/link-vmlinux.sh
with parameters lib/lib.a lib/built-in.o FORCE
and am greeted with this error:
gps@gps-HP-ProBook-4540s:~/andsrc/kernel/msm$ ./scripts/link-vmlinux.sh lib/lib.a lib/built-in.o FORCE
trap: SIGHUP: bad trap
Since this output has :
, this probably explains the original make error.
Now, disabling the line containing trap does not help, we get another error:
gps@gps-HP-ProBook-4540s:~/andsrc/kernel/msm$ ./scripts/link-vmlinux.sh lib/lib.a lib/built-in.o FORCE
LD vmlinux.o
./scripts/link-vmlinux.sh: 44: ./scripts/link-vmlinux.sh: -r: not found
I am not very sure what to try next. Any help is appreciated.
Solution 1:[1]
Lines 44 and 45 look something like this:
${LD} ${LDFLAGS} -r -o ${1} ${KBUILD_VMLINUX_INIT} \
--start-group ${KBUILD_VMLINUX_MAIN} --end-group
So what's happening is that $LD
and $LDFLAGS
are undefined which leaves the command to just be -r ...
, and -r
isn't a command on your system, hence the command not found.
Define $LD
and $LDFLAGS
then it will run whatever $LD
is with the $LDFLAGS
+ the remainder of the other command.
If you still have problems, add a comment and I'll look into it further.
Solution 2:[2]
Pretty old question, but I just had the same problem and I want to tell that the issue appears only if you've set CROSS_COMPILE
incorrectly. No need to comment out trap
, export explicitly LD
and LDFLAGS
or do other hacks.
Documentation is unclear in what CROSS_COMPILE
means. CROSS_COMPILE must be the path-prefix of the pre-built tools i.e. if you did
cd /files/src
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6
Then, you have to export CROSS_COMPILE=/files/src/arm-eabi-4.8/bin/arm-eabi-
, so ${CROSS_COMPILE}ld
would mean /files/src/arm-eabi-4.8/bin/arm-eabi-ld
As far as I see you were exporting it exactly as documentation shows as CROSS_COMPILE=aarch64-linux-android-
, which I guess is wrong path-prefix.
If you are building on ubuntu, consider installing gcc-aarch64-linux-gnu
, gcc-arm-linux-gnueabi
and setting CROSS_COMPILE
to /usr/bin/aarch64-linux-gnu-
Solution 3:[3]
I'm fixed CROSS_COMPILE variable to the valid path. But same error still there. Then i add
$(info VAR="$(vmlinux-deps)")
just before vmlinux call. And the issue become clear:
/usr/bin/aarch64-linux-gnu-gcc: No such file or directory Is your PATH set correctly?
I have installed g++ only, not gcc. Installing 'gcc' package solve the problem. On ubuntu:
sudo apt-get install gcc-aarch64-linux-gnu
Solution 4:[4]
I encounter the same problem as you.
The instruction in the document(http://source.android.com/source/building-kernels.html) is right but don't tell us we should run the following command to setup cross compile env:
cd <aosp source code tree>
source build/envsetup.sh
lunch aosp_angler-userdebug # i want to build kernel for angler(nexus 6p)
the upper codes will init building environment for us
the building environment includes cross compile tool under /prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/
then, you run the following commands to build kernel:
cd msm # my angler's kernel is under ...kernel/msm
export ARCH=arm64 # angler is arm64
export CROSS_COMPILE=aarch64-linux-android- # use arm64 cross compile tool
make angler_defconfig # run kernel config
make -j16# build kernel with all cpu cores( amd4800H cpu has 16 cores)
Solution 5:[5]
With the inspiring way of @dmitry-screwer, I figured out the real error is missing
aarch64-linux-gnu-gcc
. Since toolchains were cloned from https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9
, it makes no sense that some files would be missing. Then I realized files on git remote might be changed and not suitable to my makefiles. So I fetched android-5.1.1_r37
tag which was created years ago to get the missing gcc successfully.
Solution 6:[6]
Removed trap
line from link-vmlinux.sh
and started make
. Kernel builds and runs successfully.
Running link-vmlinux.sh
standalone still gives error, but make
succeeds.
Solution 7:[7]
Check the version of aarch64-linux-android-4.9
. If there is a mismatch, such errors may occur:
Makefile:796: *** multiple target patterns. Stop.
devicetable-offsets.c: 11:2: error: unexpected token at start of statement. DEVID_FIELD
arch/arm64/Makefile:57: Detected assembler with broken .inst; disassembly will be unreliable
Solution: See all branch at: https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/+refs and download the branch of your Android version.
for example:
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9 --depth=1 -b android-8.1.0_r81
Also, aarch64-linux-android-gcc
was removed for new branch, so you need to download earlier version.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | jdek |
Solution 2 | |
Solution 3 | Dmitry Screwer |
Solution 4 | |
Solution 5 | MagicKyle |
Solution 6 | GPS |
Solution 7 |