简体   繁体   English

无法交叉编译mips

[英]Unable to cross-compile for mips

I tried to cross compile the simple hello.c using mips cross compiler which throws me error. 我试图使用mips交叉编译器交叉编译简单的hello.c,这使我出错。

Below is the error 下面是错误

satya@satya-dev:~/Test/kernel/check$ make ARCH=mips CROSS_COMPILE=mips-buildroot-linux-uclib-
make -C /opt/toolchains/crosstools-mips-gcc-5.3-linux-4.1-uclibc-1.0.12-binutils-2.25-NPTL/usr/bin/ M=/home/satya/Test/kernel/check modules
make[1]: Entering directory '/opt/toolchains/crosstools-mips-gcc-5.3-linux-4.1-uclibc-1.0.12-binutils-2.25-NPTL/usr/bin'
make[1]: *** No rule to make target 'modules'.  Stop.
make[1]: Leaving directory '/opt/toolchains/crosstools-mips-gcc-5.3-linux-4.1-uclibc-1.0.12-binutils-2.25-NPTL/usr/bin'
Makefile:7: recipe for target 'all' failed
make: *** [all] Error 2

My Makefile is: 我的Makefile是:

obj-m := hello.o
#KDIR := /lib/modules/$(shell uname -r)/build/
KDIR := /opt/toolchains/crosstools-mips-gcc-5.3-linux-4.1-uclibc-1.0.12-binutils-2.25-NPTL/usr/bin/
#PWD = $(shell pwd)

all:
        $(MAKE) -C $(KDIR) M=$(shell pwd) modules
clean:
        $(MAKE) -C $(KDIR) M=$(shell pwd) clean

I added the compiler path to /bin also 我也将编译器路径添加到/ bin

satya@satya-dev:~/Test/kernel/check$ echo $PATH
/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/sbin:/opt/toolchains/crosstools-mips-gcc-5.3-linux-4.1-uclibc-1.0.12-binutils-2.25-NPTL:/opt/toolchains/crosstools-mips-gcc-5.3-linux-4.1-uclibc-1.0.12-binutils-2.25-NPTL/usr/bin

Even compiler works fine without makefile 即使没有makefile,编译器也能正常工作

satya@satya-dev:~/Test/kernel/check$ /opt/toolchains/crosstools-mips-gcc-5.3-linux-4.1-uclibc-1.0.12-binutils-2.25-NPTL/usr/bin/mips-buildroot-linux-uclibc-gcc in.c -o temp
satya@satya-dev:~/Test/kernel/check$ ll
total 24
-rw-rw-r-- 1 satya satya 1135 Aug 10 05:06 hello.c
-rw-rw-r-- 1 satya satya    0 Aug 10 06:29 Module.symvers
-rw-rw-r-- 1 satya satya   52 Aug 10 07:48 modules.order
-rw-rw-r-- 1 satya satya   66 Aug 10 07:59 in.c
-rw-rw-r-- 1 satya satya  281 Aug 10 08:30 Makefile
-rwxrwxr-x 1 satya satya 5604 Aug 10 09:37 temp

I know I am doing some vague mistake, but I couldn't figure it out. 我知道我在犯一些模糊的错误,但是我无法弄清楚。 Can anyone tell me where am I going wrong? 谁能告诉我我要去哪里错了?

I know I am doing some vague mistake, but I couldn't figure it out. 我知道我在犯一些模糊的错误,但是我无法弄清楚。 Can anyone tell me where am I going wrong? 谁能告诉我我要去哪里错了?

No, it's no "vague mistake". 不,这不是“模糊的错误”。 Your Makefile has valid form , but the contents are pretty much non-sensical. 您的Makefile具有有效的格式 ,但是其中的内容几乎没有意义。

In your command-line make invocation, you do not name a target, so make chooses the default (first) one in your Makefile, 'all'. 在命令行make调用中,您没有命名目标,因此make在Makefile中选择默认(第一个)“ all”。 This is probably what you want, as far as it goes. 就目前而言,这可能就是您想要的。

The recipe for target 'all' contains only one command: 目标“全部”的配方仅包含一个命令:

  $(MAKE) -C $(KDIR) M=$(shell pwd) modules 

This runs a sub- make in directory $(KDIR) , which is surprising because it does not look like the value set for KDIR is part of the project you are trying to build. make$(KDIR)目录中运行一个子make ,这令人惊讶,因为它看起来像为KDIR设置的值似乎不是您要构建的项目的一部分。

The sub- make is asked to build a target named 'modules', and the error message indicates that make does not have any rule for how to do so. 要求该子make构建一个名为“ modules”的目标,并且错误消息表明make对此没有任何规则。 Probably it does not see a makefile (under any of the names it recognizes) in the build directory, but if it does see one, then it does not contain a rule for that target. 它可能在构建目录中看不到一个makefile(使用它可以识别的任何名称),但是如果确实看到一个makefile,则它不包含该目标的规则。 I note that the Makefile you present has no rule for such a target, either, so I have no idea where that comes from. 我注意到您提供的Makefile也没有针对此类目标的规则,因此我也不知道其来源。

Even compiler works fine without makefile 即使没有makefile,编译器也能正常工作

Well that's good news, at least. 好吧,至少这是个好消息。

The key to cross-compiling is to use the correct toolchain for the purpose. 交叉编译的关键是为此目的使用正确的工具链。 You can do this in several ways, but most of them start with defining some standard make variables appropriately. 您可以通过多种方式来执行此操作,但是大多数方式都以适当地定义一些标准make变量开始。 For example: 例如:

tooldir = /opt/toolchains/crosstools-mips-gcc-5.3-linux-4.1-uclibc-1.0.12-binutils-2.25-NPTL/usr/bin
CC = $(tooldir)/mips-buildroot-linux-uclibc-gcc
LD = $(CC)

The CC variable names the C compiler, and the LD variable names the linker. CC变量命名为C编译器,而LD变量命名为链接器。 There are other variables you might want or need to set, too, such as CFLAGS for any C compiler flags you want to use, and LDFLAGS for any linker flags. 您可能还需要设置其他变量,例如,对于要使用的任何C编译器标志,请使用CFLAGS ;对于任何链接器标志,请使用LDFLAGS

There are several ways you could go from there, but the very simplest would be to name the default target "hello" instead of "all": 有几种方法可以解决,但最简单的方法是将默认目标命名为“ hello”,而不是“ all”:

hello:

And that's probably all you need to build the "hello" program specifically. 这可能就是您专门构建“ hello”程序所需要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM