关于 configure 的交叉编译

在使用configure之前,首先要明白怎么用,

configure -h 查看帮助,看需要配置哪些环境变量

Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
LIBS libraries to pass to the linker, e.g. -l<library>
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
you have headers in a nonstandard directory <include dir>
CPP C preprocessor
CXX C++ compiler command
CXXFLAGS C++ compiler flags
PYTHON the Python interpreter
LT_SYS_LIBRARY_PATH
User-defined run-time library search path.
CXXCPP C++ preprocessor
PKG_CONFIG path to pkg-config utility
PKG_CONFIG_PATH
directories to add to pkg-config's search path
PKG_CONFIG_LIBDIR
path overriding pkg-config's built-in search path
URCU_CFLAGS C compiler flags for URCU, overriding pkg-config
URCU_LIBS linker flags for URCU, overriding pkg-config
CLASSPATH Java class path

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.

还有host,build,target参数

build:执行代码编译的主机,正常的话就是你的主机系统。这个参数一般由config.guess来猜就可以。当然自己指定也可以。
host:编译出来的二进制程序所执行的主机,因为绝大多数是如果本机编译,本机执行。所以这个值就等于build。只有交叉编译的时候(也就是本机编译,其他系统机器执行)才会build和host不同。用host指定运行主机。
target:这个选项只有在建立交叉编译环境的时候用到,正常编译和交叉编译都不会用到。他用build主机上的编译器,编译一个新的编译器(binutils, gcc,gdb等),这个新的编译器将来编译出来的其他程序将运行在target指定的系统上。
让我们以编译binutils为例:
1. `./configure --build=mipsel-linux --host=mipsel-linux --target=mipsel-linux' 
说明我们利用mipsel-linux的编译器对binutils进行编译,编译出来的binutils运行在mipsel-linux,这个binutils用来编译能够在mipsel-linux运行的代码。“当然没有人会用这个选项来编译binutils”

 

然后按照帮助信息设置环境变量

export CC="riscv64-unknown-linux-gnu-gcc"  #gcc编译器
export CXX="riscv64-unknown-linux-gnu-g++" #g++编译器
export LDFLAGS = -L/home/aaa/workd1-2/tina-d1-h/prebuilt/gcc/linux-x86/riscv/toolchain-thead-glibc/riscv64-glibc-gcc-thead_20200702/sysroot/lib64/lp64 #toolchain使用的库地址
export LIBS= -lblkid -lncurses #使用到的库的名称 lib前缀省略掉, libblkid.so libncurses.so

export CFLAGS=-I/home/aaa/workd1-2/tina-d1-h/prebuilt/gcc/linux-x86/riscv/toolchain-thead-glibc/riscv64-glibc-gcc-thead_20200702/sysroot/usr/include #toolchain用到的头文件地址

make build

cd build

../configure --prefix=/home/aaa/workd1-2/code/soft/_install --host=riscv64-unknown-linux-gnu

make

祝你好运!!!

 

posted on   zxddesk  阅读(85)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示