在arm板上简单运行main.cpp(hello world)有2种方法:
(1). 使用build.sh编译链接
(2). 直接使用命令行进行编译链接
(3). 使用makefile编译链接

linux和arm共享文件: 之前通过rootpath配过

一般把程序放在mnt路径下
/home/abedg/NfsRoot/target/mnt

方法一: 使用build.sh编译链接

arm-linux-g++: 交叉编译工具

mtune=cortex-a7: 核心板处理器是cortex-a7

std=c++11: 使用c++11进行编译

-lpthread: gcc编译使用了POSIX thread程序通常需要增加额外的选项

-lm: -l是链接作用,-lm是链接数学库

-lstdc++: 编译C++程序,需要用到C++库,故需要加上-lstdc++

-lrt: 链接添加实时库(rt: real time)

-dl: 加载动态链接库

-O3: 最高优化级别. 除了执行-O2所有的优化选项外,一般都是采取向量化算法,提高代码的并行执行程度,利用现代CPU中的流水线, Cache等.

(1). /home/abedg/NfsRoot/target/mnt写入
main.cpp
arm板上简单运行main.cpp

(2). 建立build.sh文件,书写以下内容

arm板上简单运行main.cpp

其中: arm-linux-g++, 是交叉编译工具链
./videostitch, 是生成可执行文件名videostitch
(2). 运行完毕后,将会出现可执行文件名videostitch

arm板上简单运行main.cpp

(3).在SecureCRT串口
sgks login: root
输入pwd, 则显示/root, 其实相当于ubuntu下的
/home/abedg/NfsRoot/target/root
一般情况下,需要运行的程序都放在
/home/abedg/NfsRoot/target/mnt目录下
故: cd ..
然后 cd mnt, 即可得到/mnt目录下
运行 ./videostitch, 即可得到如下结果:

arm板上简单运行main.cpp

方法二: 直接使用命令行进行编译链接

(1). /home/abedg/NfsRoot/target/mnt写入
main.cpp
arm板上简单运行main.cpp

(2). /home/abedg/buildroot/output/host/bin/arm-linux-g++ -o hello main.cpp
其中:
arm-linux-g++: 交叉编译工具
-o hello 生成可执行文件
main.cpp: 所需要的文件
arm板上简单运行main.cpp
此时可看到生成了hello可执行文件

(3). 在SecureCRT串口
sgks login: root
输入pwd, 则显示/root, 其实相当于ubuntu下的
/home/abedg/NfsRoot/target/root
一般情况下,需要运行的程序都放在
/home/abedg/NfsRoot/target/mnt目录下
故: cd ..
然后 cd mnt, 即可得到/mnt目录下
运行 ./hello, 即可得到如下结果:
arm板上简单运行main.cpp

方法三:使用makefile编译链接

makefile基本格式: 目标,依赖,命令
main: 生成目标文件mainmake
main.cpp: 依赖项
命令行: /home/abedg/buildroot/output/host/bin/arm-linux-g++ -o main main.cpp
(1).
arm板上简单运行main.cpp
命令前面一定是tab键
(2).
生成可执行文件main
arm板上简单运行main.cpp

(3). SecureCRT
arm板上简单运行main.cpp

相关文章:

  • 2022-12-23
  • 2021-10-21
  • 2021-09-27
  • 2022-12-23
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-20
  • 2022-12-23
  • 2021-06-02
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
相关资源
相似解决方案