交叉編譯的簡單心得

2021-07-06 10:39:46 字數 1231 閱讀 9451

交叉編譯,就是在乙個平台上生成另乙個平台上的可執行**。有時是因為目的平台上不允許或不能夠安裝我們所需要的編譯器,而我們又需要這個編譯器的某些特徵;有時是因為目的平台上的資源貧乏,無法執行我們所需要編譯器;這個時候就需要用到交叉編譯。

以下是交叉編譯的乙個例子(目標機器是使用的linux2.6.34的核心版本),makefile檔案:

target = ***_module

objs = ***1.o ***2.o

extra_cflags += -w -g

kdir = /home/redhat/desktop/amc718_bsp_source_release3/kernel/linux-2.6.34.6

pwd = $(shell pwd)

obj-m := $(target).o

$(target)-objs := $(objs)

default:

make -c $(kdir) m=$(pwd) modules arch=powerpc cross_compile=/opt/freescale/usr/local/gcc-4.5.55-eglibc-2.11.55/

powerpc-linux-gnu/bin/powerpc-linux-gnu-

clean:

-rm -f *.o *.ko .*.cmd .*.flags *.mod.c *~ core .depend .tmp_versions

depend .depend dep:

$(cc) $(cflags) -m *.c > .depend

ifeq (.depend,$(wildcard .depend))

include .depend

endif

1、該檔案先指明模組原始碼中各檔案的依賴關係,以及要生成的目標模組名。

2、-c $(kdir) 指明跳轉到核心原始碼目錄下讀取那裡的makefile;m=$(pwd) 表明然後返回到當前目錄繼續讀入、執行當前的makefile

3、depend 的作用:如果不使用這個功能, 則當你修改乙個標頭檔案時, 必須重新把所有的原始檔都編譯一次, 使用depend ,就可只編譯包含此標頭檔案的原始檔,可大大節省時間。

depend .depend dep:

$(cc) $(cflags) -m *.c > .depend

gcc 分析原始檔然後產生乙個標頭檔案的列表和它的依賴關係。

編譯 交叉編譯

交叉編譯含義 是指在乙個平台上生成另乙個平台上的可執行 同乙個體系結構可以執行不同的作業系統,同樣乙個作業系統也可以在不同的體系結構上執行 例 常說的x86 linux平台 指inter x86體系結構及linux for x86作業系統 x86 winnt平台 指inter x86體系結構及win...

交叉編譯(2) 交叉編譯鏈

什麼是交叉編譯鏈 明白了什麼是交叉編譯,那我們來看看什麼是交叉編譯鏈。首先編譯過程是按照不同的子功能,依照先後順序組成的乙個複雜的流程,如下圖 那麼編譯過程包括了預處理 編譯 彙編 鏈結等功能。既然有不同的子功能,那每個子功能都是乙個單獨的工具來實現,它們合在一起形成了乙個完整的工具集。同時編譯過程...

交叉編譯 Go 交叉編譯 跨平台編譯

golang 支援交叉編譯,在乙個平台上生成另乙個平台的可執行程式 cgo enabled 0 goos linux goarch amd64 go build main.go cgo enabled 0 goos windows goarch amd64 go build main.go cgo ...