以 arm-ca9-linux-gnueabihf-6.5 举例:
1、添加编译链至PATH:
只对当前终端有效,关闭后失效:
export PATH=/home/xxx/arm-ca9-linux-gnueabihf-6.5/bin:$PATH
注:持久化需在 /etc/bashrc 文件末尾追加:
export PATH=$PATH:/home/xxx/arm-ca9-linux-gnueabihf-6.5/bin
2、使用下载的cc进行编译,设定相关参数
// 动态库
CGO_ENABLED=1 CC=arm-linux-gcc GOARCH=arm go build -tags="xx xx xx" -buildmode=c-shared -ldflags '-s' -o libDEIoTClient.so .
// 静态库
CGO_ENABLED=1 CC=arm-linux-gcc GOARCH=arm go build -tags="xx xx xx" -buildmode=c-archive -o libDEIoTClient.a .
3、查看库文件的信息是否正确
动态库:
file x.so
x.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, Go BuildID=pKJxcubjdkN_mc7bbt3Y/pV6mtSxaMdejTSVdLihF/wl56JigJ4NuFMLRLmFCx/Iw_TiLVkVgDPjWQ_cp53, stripped
readelf -h x.a
File: libDEIoTClient.a(go.o)
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32