交叉编译zeromq以及go交叉编译cgo依赖

交叉编译zeromq,并编译go可执行文件

交叉编译libsodium

./configure --host=aarch64-himix100-linux --prefix=/home/udsafe/ && make && make install

交叉编译libzmq

./configure --host=aarch64-himix100-linux --prefix=/home/udsafe/ && make && make install

交叉编译libuuid

./configure --host=aarch64-himix100-linux --prefix=/home/udsafe/ && make && make install

交叉编译czmq (需要uuid则先编译下uuid)

./configure --host=aarch64-himix100-linux --prefix=/usr/local/udsafe libzmq_CFLAGS='-I/usr/local/udsafe/include' libzmq_LIBS='-L/usr/local/udsafe/lib -lzmq -L/opt/hisi-linux/x86-arm/aarch64-himix100-linux/aarch64-linux-gnu/lib64 -lstdc++'

make check

此时会有报错信息,不用处理,重新make一下即可

cd src/.libs

cp ../libczmq.la libczmq.lai

make install

编译完成

交叉编译libpcap

./configure --host=aarch64-himix100-linux --prefix=/home/udsafe/ && make && make install

  

交叉编译go环境

去git拉取go编译环境放置/usr/local/go

在交叉编译环境导入环境变量

export PATH="/usr/local/go/bin:/opt/hisi-linux/x86-arm/aarch64-himix100-linux/bin:$PATH"

导入国内代理

export GO111MODULE=on

export GOPROXY=https://goproxy.cn

 

  

创建go编译目录

mkdir -p /home/dkth/src/github.com

临时修改gopath路径

export GOPATH="/home/dkth"

将编译的项目放到/home/dkth/src下

dkth_check_environment (是个目录)

mv dkth_check_environment /home/dkth/src
root@ubuntu-VirtualBox:/home/dkth/src# tree dkth_check_environment 
dkth_check_environment
├── check
│   ├── minio.go
│   ├── mqtt.go
│   └── zmq.go
├── dkth_check_environment (编译出来的可执行文件)
├── go.mod
├── go.sum
└── main.go

交叉编译需要zeromq 的cgo程序

 PKG_CONFIG_PATH=/home/udsafe/lib/pkgconfig/ CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-himix100-linux-gcc CGO_CFLAGS=-I/home/udsafe/include CGO_LDFLAGS="-L/home/udsafe/lib -L/opt/hisi-linux/x86-arm/aarch64-himix100-linux/aarch64-linux-gnu/lib64 -lstdc++ -luuid" go build

编译完成会多出一个dkth_check_environment 可执行文件,在arm环境下执行验证即可

./dkth_check_environment 

  

交叉编译libpcap go测试代码tcp抓包与创建sqlite.db

mv dkth_test /home/dkth/src

cd /home/dkth/src/

root@ubuntu-VirtualBox:/home/dkth/src# tree dkth_test/
dkth_test/
├── go.mod
├── go.sum
└── main.go

CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-himix100-linux-gcc CGO_CFLAGS='-I/home/udsafe/include' CGO_LDFLAGS='-L/home/udsafe/lib' go build

编译完成多出一个可执行文件,arm环境测试验证即可

  

posted @ 2020-11-24 11:16  LDoctorF  阅读(835)  评论(0编辑  收藏  举报