侧边栏壁纸
博主头像
Eoser's page! 博主等级

@学习@生活@自己

  • 累计撰写 114 篇文章
  • 累计创建 29 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

Golang交叉编译第二弹--Jenkins安装C环境

eoser
2023-03-28 / 0 评论 / 0 点赞 / 0 阅读 / 0 字

golang项目使用了SQLITE3的库

书接上回,终于把源码都正常编译过了,但是!!!执行编译的二进制文件时,报错了,原因就是 "export CGO_ENABLED=0" ,因为sqlite3库编译需要用到gcc,所以这里改为"export CGO_ENABLED=1"

打开CGO后的问题

打开cgo后,编译时找不到gcc!!! 好办,apt装一个吧。 纳尼,没权限! sudo吧。 啊?没sudo!!! su root呢?靠!有密码,进不了! 那我下载二进制文件然后配环境变量把! 龟速下载文件很久后。 下的什么玩意?源码!!!我就是缺失gcc,我要你源码有何用? 二进制文件呢?找啊找,找不到!崩溃!

在docker jenkins中正确的gcc安装方式

哈哈!docker可以直接进入root的!

docker exec -it --user root jenkins bash

然后干啥?当然时安装gcc啊!呃......比乌龟还慢的速度! 不能忍,修改apt镜像! 靠!没有vi编辑器!只能命令行手搓了!啊!Debian 11的系统,我还以为是Ubuntu呢!

# 虽然可能不再会用到了,还是先备个份
cp sources.list sources.list.old

# 清空一下,并输入,咱不贪,能输多少就输入多少
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free" > sources.list
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free" >> sources.list
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free" >> sources.list
echo "deb https://security.debian.org/debian-security bullseye-security main contrib non-free" >> sources.list

# 换源基本盘,跟新数据和软件
apt update
apt upgrade

# 哈哈,颤抖吧,安装gcc
apt install gcc
# 再安装下基本软件
apt install vim

# 发现 jenkins 不能修改密码,本来安装了sudo的,不能用。最后直接给 root 改个密码,方便使用吧
passwd

OK,万事皆备,只欠编译

修改脚本中的cgo参数,具体脚本可以搜索Gloang交叉编译寻找另一篇文章

export CGO_ENABLED=1

完蛋,又双叒叕报错了

又报错了!下一弹再解决吧

......
# runtime/cgo
gcc: error: x86_64: No such file or directory
gcc: error: unrecognized command-line option '-arch'
......
# runtime/cgo
gcc: error: arm64: No such file or directory
gcc: error: unrecognized command-line option '-arch'
......
0

评论区