linux
如何交叉编译Python到ARM-Linux平台?
一、如何交叉编译Python到ARM-Linux平台?
先运行以下几步:
[plain] view plaincopytar zxf sqlite-amalgamation-3.5.6.tar.gz cd sqlite-3.5.6 ./configure --host=arm-linux --prefix=/usr/local/arm/3.3.2 --enable-shared --disable-readline --disable-dynamic-extensions 以上是把sqlite解压缩,然后做一些配置,这里,我希望sqlite到时候安装到/usr/local/arm/3.3.2里,要生成动态链接库,不要readline,不要sqlite的动态扩展。
然后编辑Makefile,把CFLAG和CXXFLAG中的-g去掉,我们不用debug sqlite。
接下来就可以编译和安装sqlite了:
[plain] view plaincopymake make install 这一步就完成了sqlite的编译和安装了。
二、如何编译arm linux的go?
Golang也就是Go语言,现在已经发行到1.4.1版本了,语言特性优越性和背后Google强大靠山什么的就不多说了。Golang的官方提供了多个平台上的二进制安装包,遗憾的是并非没有发布ARM平台的二进制安装包。ARM平台没办法直接从官网下载二进制安装包来安装,好在Golang是支持多平台并且开源的语言,因此可以通过直接在ARM平台上编译源代码来安装。整个过程主要包括编译工具配置、获取Golang源代码、设置Golang编译环境变量、编译、配置Golang行环境变量等步骤。
注:本文选用树莓派做测试,因为树莓派是基于ARM平台的。
1、编译工具配置
据说下个版本的golang编译工具要使用golang自己来写,但目前还是使用C编译工具的。因此,首先要配置好C编译工具:
1.1 在Ubuntu或Debian平台上可以使用sudo apt-get install gcc libc6-dev命令安装,树莓派的RaspBian系统是基于Debian修改的,所以可以使用这种方法安装。
1.2 在RedHat或CentOS 6平台上可以使用sudo yum install gcc libc-devel命令安装。
安装完成后可以输入 gcc --version命令验证是否成功安装。
2、获取golang源代码
2.1 直接从官网下载源代码压缩包。
golang官网提供golang的源代码压缩包,可以直接下载,最新的1.4.1版本源代码链接:https://storage.googleapis.com/golang/go1.4.1.src.tar.gz
2.2 使用git工具获取。
golang使用git版本管理工具,也可以使用git获取golang源代码。推荐使用这个方法,因为以后可以随时获取最新的golang源代码。
2.2.1 首先确认ARM平台上已经安装了git工具,可以使用git --version命令确认。一般linux平台都安装了git,没有的话可以自行安装,不同平台的安装方法可以参考:http://git-scm.com/download/linux
2.2.2 克隆远程golang的git仓库到本地
在终端cd到你想要安装golang的目录,确保该目录下没有名为go的目录。然后以下命令获取代码仓库:
git clone https://go.googlesource.com/go
大陆地区可能会获取失败,在不翻墙的情况下我试了几次都没成功,原因大家都懂的。好在google已经将golang也托管到github上面,所以也可以通过下面命令获取:
git clone https://github.com/golang/go.git
视网络情况,下载可能需要不少时间。我2M的带宽花了将近两个小时才下载完,虽然整个项目不过几十兆= =
下载完成后,可以看到目录下多了一个go目录,里面即为golang的源代码,在终端上执行cd go命令进入该目录。
执行下面命令检出go1.4.1版本的源代码,因为现在已经有新的代码提交上去了,最新的代码可能不是最稳定的:
git checkout go1.4.1
至此,最新1.4.1发行版的源代码获取完毕
3、设置golang的编译环境变量
主要有GOROOT、GOOS、GOARCH、GOARM四个环境变量需要设置,先解释四个环境变量的意义。
3.1 GOROOT
主要代表golang树结构目录的路径,也就是上面git检出的go目录。一般可以不用设置这个环境变量,因为编译的时候默认会以go目录下src子目录中的all.bash脚本运行时的父目录作为GOROOT的值。为了保险起见,可以直接设置为go目录的路径。
3.2 GOOS和GOARCH
分别代表编译的目标系统和平台,可选值如下:
GOOS GOARCH
darwin 386
darwin amd64
dragonfly 386
dragonfly amd64
freebsd 386
freebsd amd64
freebsd arm
linux 386
linux amd64
linux arm
netbsd 386
netbsd amd64
netbsd arm
openbsd 386
openbsd amd64
plan9 386
plan9 amd64
solaris amd64
windows 386
windows amd64
需要注意的是这两个值代表的是目标系统和平台,而不是编译源代码的系统和平台。树莓派的RaspBian是linux系统,所以这些GOOS设置为linux,GOARCH设置为arm。
3.3 GOARM
表示使用的浮点运算协处理器版本号,只对arm平台有用,可选值有5,6,7。如果是在目标平台上编译源代码,这个值可以不设置,它会自动判断需要使用哪一个版本。
总结下来,在树莓派上设置golang的编译环境变量,可编辑$HOME/.bashrc文件,在末尾添加下面内容:
export GOROOT=你的go目录路径
export GOOS=linux
export GOARCH=arm
编辑完后保存,执行source ~/.bashrc命令让修改生效。
4、编译源代码
环境变量配置完成自后就可以开始编译源代码。在go目录下的src子目录中,主要有all.bash和make.bash两个脚本(另外还有两个all.bat和make.bat脚本适用于window平台)。编译实际上就是执行其中一个脚本,两者的区别在于all.bash在编译完成后还会执行一些测试套件。如果希望只编译不测试,可以运行make.bash脚本。使用cd命令进入go下src目录,执行./all.bash或者./make.bash命令即可开始编译。由于硬件情况不同,编译耗费的时间不同。在我的B型树莓派编译过程花费了将近半个小时,编译完成后执行的测试套件又花费了差不多一个小时,总共花费了一个半小时左右。
5、配置golang运行环境变量
编译完成后,go目录下会生成bin目录,里面就是go的运行脚本。为了以后使用方法,可以将这个bin路径添加到PATH环境变量中。同样编辑~/.bashrc文件,因为前面设置过GOROOT环境变量指向go目录了,所以只需要在末尾加上
export PATH=$PATH:$GOROOT/bin
保存后同样执行source ~/.bashrc命令让环境变量生效。
至此,golang源代码编译安装成功。执行go version应该就能看到当前golang的版本信息,表示编译安装成功。
三、linux交叉编译是什么?
编译器是将源代码转换为可执行代码的程序。像所有程序一样,编译器运行在特定类型的计算机上,输出的新程序也运行在特定类型的计算机上。
运行编译器的计算机称为主机,运行新程序的计算机称为目标。当主机和目标是同一类型的机器时,编译器是本机编译器。当宿主和目标不同时,编译器是 交叉编译器。
四、qt的程序在arm-linux-g++下怎么交叉编译?
用交叉编译工具(arm-linux-g++等)把你自己的qt程序用嵌入式版本的qt库交叉编译一下然后烧写到开发板上就可以执行了,当然你qt程序所用到的库也要放上去,并设置到路径(QTDIR,PATH,LIBRARY_PATH)等等
五、ubuntu怎么安装arm交叉编译工具?
1、下载文件:安装包:arm-linux-gcc-4.5.1-v6-vfp-20120301.tgz2、开始安装(建议大家新建一个文件夹),然后将文件复制到新建的文件夹中输入命令: sudo tar xvzf arm-linux-gcc-4.5.1-v6-vfp-20120301.tgz安装完成后,输入ls命令,可以看到一个opt文件夹,3.修改环境变量,把交叉编译器的路径加入到PATH:利用tab键的补齐功能进入该路径输入pwd命令,查看当前路径的绝对路径/home/cf/ARM/opt/FriendlyARM/toolschain/4.5.1/bin
六、ubuntu怎么安装arm交叉编译器?
1、下载文件:安装包:arm-linux-gcc-4.5.1-v6-vfp-20120301.tgz2、开始安装(建议大家新建一个文件夹),然后将文件复制到新建的文件夹中输入命令: sudo tar xvzf arm-linux-gcc-4.5.1-v6-vfp-20120301.tgz安装完成后,输入ls命令,可以看到一个opt文件夹,3.修改环境变量,把交叉编译器的路径加入到PATH:利用tab键的补齐功能进入该路径输入pwd命令,查看当前路径的绝对路径/home/cf/ARM/opt/FriendlyARM/toolschain/4.5.1/bin
七、arm-linux-gcc怎么编译文件?
可以使用gcc命令进行编译: 例子: gcc -o hello hello.c #在这里hello.c是源文件,hell为目标输出文件 通过编译器编译主要是经过:预处理,汇编,编译和链接的过程;
八、什么是交叉编译,为什么要使用交叉编译?
简单地说,就是在一个平台上生成另一个平台上的可执行代码。
同一个体系结构可以运行不同的操作系统;同样,同一个操作系统也可以在不同的体系结构上运行。举例来说,我们常说的x86 Linux平台实际上是Intel x86体系结构和Linux for x86操作系统的统称;而x86 WinNT平台实际上是Intel x86体系结构和Windows NT for x86操作系统的简称。九、arm linux和linux的区别?
相对于ARM linux,我们说的普通linux指的是X86 linux,他们都是linux系统,但是由于ARM和X86是不同的CPU架构,他们的指令集不同,所以软件编译环境不同,软件代码一般不能互用,一般需要进行兼容性移植。
X86是经典的CISC指令集,指令集复杂,功能多,串行执行,但是也意味着执行效率低下,但性价比突出,所以称为民用终端的主流处理器内置指令集。Intel和AMD的家用处理器都是X86指令集。以X86为代表的CISC,理论并发线程1-2条。ARM是Advanced RISC Machine 的缩写。它的指令集比RISC还要精简。通常使用ARM架构处理器的机型,多为嵌入式或者便携机。主频通常不高,现在高通公司的ARM架构处理器有1.0GHz的,已经算相当高了。另外,ARM 7沿用冯·诺依曼结构;而从ARM 9以后,就都采用了哈佛结构。ARM的并发线程,理论上有4条左右,处理效率较X86高不少。十、ARM怎么用linux?
相对于ARM linux,我们说的普通linux指的是X86 linux,他们都是linux系统,但是由于ARM和X86是不同的CPU架构,他们的指令集不同,所以软件编译环境不同,软件代码一般不能互用,一般需要进行兼容性移植。 X86是经典的CISC指令集,指令集复杂,功能多,串行执行,但是也意味着执行效率低下,但性价比突出,所以称为民用终端的主流处理器内置指令集。Intel和AMD的家用处理器都是X86指令集。以X86为代表的CISC,理论并发线程1-2条。ARM是Advanced RISC Machine 的缩写。它的指令集比RISC还要精简。通常使用ARM架构处理器的机型,多为嵌入式或者便携机。主频通常不高,现在高通公司的ARM架构处理器有1.0GHz的,已经算相当高了。另外,ARM 7沿用冯·诺依曼结构;而从ARM 9以后,就都采用了哈佛结构。ARM的并发线程,理论上有4条左右,处理效率较X86高不少。
热点信息
-
在Python中,要查看函数的用法,可以使用以下方法: 1. 使用内置函数help():在Python交互式环境中,可以直接输入help(函数名)来获取函数的帮助文档。例如,...
-
一、java 连接数据库 在当今信息时代,Java 是一种广泛应用的编程语言,尤其在与数据库进行交互的过程中发挥着重要作用。无论是在企业级应用开发还是...
-
一、idea连接mysql数据库 php connect_error) { die("连接失败: " . $conn->connect_error);}echo "成功连接到MySQL数据库!";// 关闭连接$conn->close();?> 二、idea连接mysql数据库连...
-
要在Python中安装modbus-tk库,您可以按照以下步骤进行操作: 1. 确保您已经安装了Python解释器。您可以从Python官方网站(https://www.python.org)下载和安装最新版本...