当前位置:网站首页>配置交叉编译工具链和环境变量
配置交叉编译工具链和环境变量
2022-07-04 05:30:00 【宁静致远2021】
配置交叉编译工具链和环境变量
原文链接:https://blog.csdn.net/qq_56926420/article/details/122890366
1 设置交叉编译工具链
交叉编译工具链用来在Ubuntu主机上编译应用程序,而这些应用程序是在ARM等其他平台上运行。
设置交叉编译工具主要是设置PATH, ARCH和CROSS_COMPILE三个环境变量,下面介绍具体设置方法。
设置这3个环境变量有多种方法,任意选择其中一种方法即可,建议使用“永久生效”的方法。录制视频时我会使用多种开发板,所以在视频里我总是使用“临时生效”的方法。
库环境变量设置:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH=/usr/local/X11/lib:$LD_LIBRARY_PATH/
1.1 永久生效
如需永久修改,请修改用户配置文件。
注意:如果不会使用vim命令,可以使用图形化的编辑工具,执行:gedit ~/.bashrc
vim ~/.bashrc
(1)
在行尾添加或修改,加上下面几行(第3行第4行为一行命令):
export ARCH=arm
export CROSS_COMPILE=arm-buildroot-linux-gnueabihf-
export PATH=$PATH:/home/book/100ask_imx6ull-sdk/ToolChain/arm-buildroot-linux-gnueabihf_sdk-buildroot/bin
设置完毕后,要执行 source ~/.bashrc 命令使其生效,这条命令是加载这些设置的环境变量。
设置完毕后,要执行 source ~/.bashrc 命令使其生效,这条命令是加载这些设置的环境变量。
[email protected]:~$ source ~/.bashrc
[email protected]:~$ arm-buildroot-linux-gnueabihf-gcc -v
1.2 临时生效
也可以手工执行“export”命令设置环境变量,该设置只对当前终端有效(另开一个终端需要再次设置)。
(1)
执行以下3个命令,第3个命令很长,需要包含第四行全部复制:
[email protected]:~$ export ARCH=arm
[email protected]:~$ export CROSS_COMPILE=arm-buildroot-linux-gnueabihf-
[email protected]:~$ export PATH=$PATH:/home/book/100ask_imx6ull-sdk/ToolChain/arm-buildroot-linux-gnueabihf_sdk-buildroot/bin
1.3 手动指定
先设置PATH环境变量,然后在make编译时指定ARCH架构 CROSS_COMPILE交叉编译工具链(执行make命令时指定的参数,只对当前命令有效;下次执行make时仍需要再次指定那些参数)。
(1) 示例
[email protected]:~$ export PATH=$PATH:/home/book/100ask_imx6ull-sdk/ToolChain/arm-buildroot-linux-gnueabihf_sdk-buildroot/bin
[email protected]:~$ make ARCH=arm CROSS_COMPILE=arm-buildroot-linux-gnueabihf-
[email protected]:~$ export PATH=$PATH:/home/book/100ask_imx6ull-sdk/ToolChain/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin
[email protected]:~$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-
2 测试交叉编译工具链
2.1 测试环境变量
[email protected]:~$ echo $ARCH
arm
[email protected]:~$ echo $CROSS_COMPILE
arm-buildroot-linux-gnueabihf-
2.2 测试交叉编译器
执行以下命令,结果见后图:
[email protected]:~$ arm-buildroot-linux-gnueabihf-gcc -v
(1).
配置环境变量一:
使用export命令直接修改PATH的值,
如交叉编译工具链安装完后,
执行以下命令或者执行
export PATH=$PATH:/opt/hisi_linux/x86-arm/arm-himix100-linux/bin
说明:/opt/hisi_linux/x86-arm/arm-himix100-linux/bin为编译安装的目录
(2).配置环境变量二:
通过修改用户目录下的~/.bashrc文件进行配置:
在行尾添加或修改,加上下面一句
export PATH=$PATH:/opt/hisi_linux/x86-arm/arm-himix100-linux/bin
设置完毕后,要执行 source ~/.bashrc 命令使其生效,这条命令是加载这些设置的环境变量。
环境变量配置方法:
直接定义
export
Shell 配置文件
与 Bash Shell 有关的配置文件主要有
/etc/profile
~/.bash_profile
~/.bash_login
~/.profile
~/.bashrc
/etc/bashrc
/etc/bash.bashrc
/etc/profile.d/*.sh
Shell 执行顺序
/etc/profiles->/.profile(/.bash_profile、~/.bash_login)
修改配置文件
全部用户、全部进程共享:/etc/bash.bashrc
一个用户、全部进程共享:~/.bashrc
shell启动方式对变量的影响
子shell进程中执行:/bin/bash会创建shell子进程和./
当前进程中执行:source和.
3 如何添加交叉编译工具链(toolchain)到环境变量?(–sysroot路径)(新:ubuntu交叉编译工具链环境变量的配置)
边栏推荐
- Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology
- BUU-Crypto-[HDCTF2019]basic rsa
- LM small programmable controller software (based on CoDeSys) note 22: error 4268/4052
- How to clone objects
- 2022g2 power station boiler stoker special operation certificate examination question bank and answers
- The data mark is a piece of fat meat, and it is not only China Manfu technology that focuses on this meat
- KMP match string
- 接地继电器DD-1/60
- js获取对象中嵌套的属性值
- ETCD数据库源码分析——初始化总览
猜你喜欢
光模块字母含义及参数简称大全
[paper summary] zero shot semantic segmentation
Actual cases and optimization solutions of cloud native architecture
Online shrimp music will be closed in January next year. Netizens call No
LM small programmable controller software (based on CoDeSys) note XXI: error 3703
(4) Canal multi instance use
Character types of C language
Topological sorting and graphical display of critical path
RSA加密应用常见缺陷的原理与实践
2022年A特种设备相关管理(电梯)考试题模拟考试平台操作
随机推荐
(4) Canal multi instance use
Remote desktop client RDP
Yyds dry goods inventory TCP & UDP
724. 寻找数组的中心下标
How much computing power does transformer have
Graduation design of small programs -- small programs of food and recipes
Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology
1480. Dynamic sum of one-dimensional array
BUU-Pwn-test_ your_ nc
left_ and_ right_ Net interpretable design
1.1 history of Statistics
Simulink与Arduino串口通信
Viewing and using binary log of MySQL
2022年A特种设备相关管理(电梯)考试题模拟考试平台操作
Halcon image calibration enables subsequent image processing to become the same as the template image
Tutle clock improved version
HMS v1.0 appointment.php editid参数 SQL注入漏洞(CVE-2022-25491)
One click filtering to select Baidu online disk files
检漏继电器JY82-2P
Zzulioj:1201: mode problem