Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 无法交叉编译mips_C_Linux_Mips_Cross Compiling - Fatal编程技术网

C 无法交叉编译mips

C 无法交叉编译mips,c,linux,mips,cross-compiling,C,Linux,Mips,Cross Compiling,我尝试使用mips交叉编译器交叉编译简单的hello.c,这会引发错误 下面是错误 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/

我尝试使用mips交叉编译器交叉编译简单的hello.c,这会引发错误

下面是错误

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
我的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
我还将编译器路径添加到/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
即使没有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
我知道我犯了一些模糊的错误,但我想不出来。谁能告诉我哪里出了问题

我知道我犯了一些模糊的错误,但我想不出来。 谁能告诉我哪里出了问题

不,这不是“模糊的错误”。您的Makefile具有有效的形式,但其内容几乎没有意义

在命令行
make
调用中,您没有命名目标,因此
make
选择Makefile中的默认(第一个)目标“all”。就目前而言,这可能是你想要的

目标“all”的配方仅包含一个命令:

这在目录
$(KDIR)
中运行一个子
make
,这令人惊讶,因为它看起来不像为
KDIR
设置的值是您尝试构建的项目的一部分

子-
make
被要求构建一个名为“modules”的目标,错误消息表明
make
没有任何关于如何构建目标的规则。可能它在构建目录中没有看到makefile(在它识别的任何名称下),但是如果它确实看到了makefile,那么它就不包含该目标的规则。我注意到,您提供的
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
至少这是个好消息

交叉编译的关键是为此目的使用正确的工具链。您可以通过几种方法来实现这一点,但大多数方法都是从适当地定义一些标准make变量开始的。例如:

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)
CC
变量命名C编译器,
LD
变量命名链接器。您可能还需要设置其他变量,例如要使用的任何C编译器标志的
CFLAGS
,以及任何链接器标志的
LDFLAGS

有几种方法可供选择,但最简单的方法是将默认目标命名为“hello”而不是“all”:

这可能就是专门构建“hello”程序所需的全部内容

我知道我犯了一些模糊的错误,但我想不出来。 谁能告诉我哪里出了问题

不,这不是“模糊的错误”。您的Makefile具有有效的形式,但其内容几乎没有意义

在命令行
make
调用中,您没有命名目标,因此
make
选择Makefile中的默认(第一个)目标“all”。就目前而言,这可能是你想要的

目标“all”的配方仅包含一个命令:

这在目录
$(KDIR)
中运行一个子
make
,这令人惊讶,因为它看起来不像为
KDIR
设置的值是您尝试构建的项目的一部分

子-
make
被要求构建一个名为“modules”的目标,错误消息表明
make
没有任何关于如何构建目标的规则。可能它在构建目录中没有看到makefile(在它识别的任何名称下),但是如果它确实看到了makefile,那么它就不包含该目标的规则。我注意到,您提供的
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
至少这是个好消息

交叉编译的关键是为此目的使用正确的工具链。您可以通过几种方法来实现这一点,但大多数方法都是从适当地定义一些标准make变量开始的。例如:

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)
CC
变量命名C编译器,
LD
变量命名链接器。您可能还需要设置其他变量,例如要使用的任何C编译器标志的
CFLAGS
,以及任何链接器标志的
LDFLAGS

有几种方法可供选择,但最简单的方法是将默认目标命名为“hello”而不是“all”:


这可能就是专门构建“hello”程序所需的全部内容。

KDIR
是指向部分内核源代码的路径,而不是交叉编译器的bin目录。您需要更像这样的东西:您的makefile目标不调用您的gcc来编译任何东西,也不提及hello.c-它们只是在KDIR中运行
make
KDIR
是指向部分内核源代码的路径,而不是交叉编译器的bin目录。你需要更像这样的东西:你的makefile目标没有调用你的gcc来编译任何东西,也没有提到hello.c-他们只是在KDIR中运行
make
。我去了目录“/opt/toolschains/crosstools-mips-gcc-5.3-linux-4.1-uclibc-1.0.12-binutils-2.25-NPTL/usr/bin”。这里我有这样的交叉编译器$ll | grep mips buildroot linux uclibc gcc lrwxrwxrwx 1 501 501 2017年5月4日17 mips buildroot linux uclibc gcc->toolchain wrapper,但我没有任何make文件。我该怎么进一步呢不,@satyaGolladi,关键是你不应该去那个目录。它包含您必须使用的工具,但您不想在那里执行构建。我已经给出了一个完整或接近完整的示例,说明了如何编写一个简单的Makefile来构建“hello”程序?您好:$(KDIR)-C$(CC)M=$(shell pwd)模块注:我是驱动程序开发新手,请耐心等待me@satyaGolladi,要从名为“hello.c”的单个源文件中构建名为“hello”的程序,可以不使用任何内容替换该行。零线配方。只需将默认目标命名为“hello”,并设置var