在华为arm64 kylin计算机上安装docker编译llama.cpp的步骤

起因是试图将另一台arm64 kylin计算机上用gcc docker 容器编译的llama.cpp文件复制到这台机器上用,结果运行报错, 想用apt安装动态库也报错了,更新目录失败。

复制代码
aaa@kylin-pc:~/bin$ ./llama-cli -v
./llama-cli: error while loading shared libraries: libssl.so.3: cannot open shared object file: No such file or directory
aaa@kylin-pc:~/bin$ sudo apt install libssl3
输入密码         
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
E: 无法定位软件包 libssl3
aaa@kylin-pc:~/bin$ sudo apt update
0% [已连接到 archive.kylinos.cn]
^C

将所需的libssl.so.3和libcrypto.so.3从另一台机器复制过来,结果又报本机的glibc、glibcxx版本过旧。

复制代码
aaa@kylin-pc:~/bin$ export LD_LIBRARY_PATH=/home/aaa/bin/lib3
aaa@kylin-pc:~/bin$ ./llama-cli -v
./llama-cli: /lib/aarch64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.32' not found (required by ./llama-cli)
./llama-cli: /lib/aarch64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by ./llama-cli)
./llama-cli: /lib/aarch64-linux-gnu/libstdc++.so.6: version `CXXABI_1.3.15' not found (required by ./llama-cli)
./llama-cli: /lib/aarch64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by ./llama-cli)
./llama-cli: /lib/aarch64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /home/aaa/bin/lib3/libssl.so.3)
./llama-cli: /lib/aarch64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /home/aaa/bin/lib3/libcrypto.so.3)
./llama-cli: /lib/aarch64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /home/aaa/bin/lib3/libcrypto.so.3)

aaa@kylin-pc:~/bin$ strings /lib/aarch64-linux-gnu/libc.so.6|grep GLIBC_2
GLIBC_2.30
aaa@kylin-pc:~/bin$ strings /lib/aarch64-linux-gnu/libstdc++.so.6 |grep GLIBCXX_3
GLIBCXX_3.4.28

再把所需的glibc、glibcxx动态库从另一台机器复制过来,还是不行

复制代码
aaa@kylin-pc:~$ ls -l bin/lib3/*
-rw-r--r-- 1 aaa aaa 4466856 10月 27  2024 bin/lib3/libcrypto.so.3
-rwxr-xr-x 1 aaa aaa 1651408 11月  1  2024 bin/lib3/libc.so.6
-rw-r--r-- 1 aaa aaa  737192 10月 27  2024 bin/lib3/libssl.so.3
lrwxrwxrwx 1 aaa aaa      19 1月   8  2023 bin/lib3/libstdc++.so.6 -> libstdc++.so.6.0.30
-rw-r--r-- 1 aaa aaa 2174296 1月   8  2023 bin/lib3/libstdc++.so.6.0.30
aaa@kylin-pc:~/bin$ export LD_LIBRARY_PATH=/home/aaa/bin/lib3
aaa@kylin-pc:~/bin$ ./llama-cli -v
./llama-cli: /home/aaa/bin/lib3/libstdc++.so.6: version `GLIBCXX_3.4.32' not found (required by ./llama-cli)
./llama-cli: /home/aaa/bin/lib3/libstdc++.so.6: version `CXXABI_1.3.15' not found (required by ./llama-cli)
./llama-cli: /lib/ld-linux-aarch64.so.1: version `GLIBC_2.35' not found (required by /home/aaa/bin/lib3/libc.so.6)

接着想用本机的gcc来编译,结果报错, 说没有c++编译器。

复制代码
aaa@kylin-pc:~/llama.cpp-master$ ../cmake-4.2.3-linux-aarch64/bin/cmake -B build -DCMAKE_BUILD_TYPE=Debug
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is unknown
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - broken
CMake Error at /home/aaa/cmake-4.2.3-linux-aarch64/share/cmake-4.2/Modules/CMakeTestCCompiler.cmake:67 (message):
  The C compiler

    "/usr/bin/cc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: '/home/aaa/llama.cpp-master/build/CMakeFiles/CMakeScratch/TryCompile-VomU50'
    
    Run Build Command(s): /home/aaa/cmake-4.2.3-linux-aarch64/bin/cmake -E env VERBOSE=1 /usr/bin/make -f Makefile cmTC_eb6b0/fast
    /usr/bin/make  -f CMakeFiles/cmTC_eb6b0.dir/build.make CMakeFiles/cmTC_eb6b0.dir/build
    make[1]: 进入目录"/home/aaa/llama.cpp-master/build/CMakeFiles/CMakeScratch/TryCompile-VomU50"
    Building C object CMakeFiles/cmTC_eb6b0.dir/testCCompiler.c.o
    /usr/bin/cc    -o CMakeFiles/cmTC_eb6b0.dir/testCCompiler.c.o -c /home/aaa/llama.cpp-master/build/CMakeFiles/CMakeScratch/TryCompile-VomU50/testCCompiler.c
    Linking C executable cmTC_eb6b0
    /home/aaa/cmake-4.2.3-linux-aarch64/bin/cmake -E cmake_link_script CMakeFiles/cmTC_eb6b0.dir/link.txt --verbose=1
    /usr/bin/ld: 找不到 crt1.o: 没有那个文件或目录
    /usr/bin/ld: 找不到 crti.o: 没有那个文件或目录
    collect2: error: ld returned 1 exit status
    /usr/bin/cc CMakeFiles/cmTC_eb6b0.dir/testCCompiler.c.o -o cmTC_eb6b0
    make[1]: *** [CMakeFiles/cmTC_eb6b0.dir/build.make:102:cmTC_eb6b0] 错误 1
    make[1]: 离开目录"/home/aaa/llama.cpp-master/build/CMakeFiles/CMakeScratch/TryCompile-VomU50"
    make: *** [Makefile:134:cmTC_eb6b0/fast] 错误 2
 
 Make will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)

CMake Error at CMakeLists.txt:2 (project):
  No CMAKE_CXX_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.

-- Configuring incomplete, errors occurred!

没辙了,只好也在本机装docker环境来编译。

1.下载docker二进制文件

复制代码
aaa@kylin-pc:~$ wget https://download.docker.com/linux/static/stable/aarch64/docker-29.3.0.tgz
无法建立 SSL 连接。
aaa@kylin-pc:~$ wget https://mirrors.aliyun.com/docker-ce/linux/static/stable/aarch64/docker-29.3.0.tgz
docker-29.3.0.tgz                            100%[=============================================================================================>]  72.91M  13.8MB/s  用时 5.5s    
2026-03-09 16:07:59 (13.3 MB/s) - 已保存 "docker-29.3.0.tgz" [76446817/76446817])
aaa@kylin-pc:~$ tar xf docker-29.3.0.tgz

官网的地址不支持wget, 浏览器下载很慢,所以改用阿里云镜像地址,很快下载完了。

2.修改配置文件,启动服务

按照网上教学文章的步骤执行。所有命令都加了sudo, 以防权限不足。

复制代码
aaa@kylin-pc:~$ mv docker/* /usr/bin/
mv: 无法创建普通文件'/usr/bin/containerd': 权限不够
aaa@kylin-pc:~$ sudo mv docker/* /usr/bin/
aaa@kylin-pc:~$ sudo vi /usr/lib/systemd/system/docker.service
aaa@kylin-pc:~$ cat /usr/lib/systemd/system/docker.service
[Unit]
 
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target

[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target

aaa@kylin-pc:~$ sudo chmod +x /usr/lib/systemd/system/docker.service

aaa@kylin-pc:~$ sudo systemctl daemon-reload
aaa@kylin-pc:~$ sudo vi /etc/docker/daemon.json
aaa@kylin-pc:~$ cat /etc/docker/daemon.json
{
	"bip": "128.128.0.1/16",
"proxies": { "http-proxy": "http://proxy.aaa:8080", 
	"https-proxy": "http://proxy.aaa:8080", 
	"no-proxy": "localhost,127.0.0.1,.example.com" },
  "registry-mirrors": ["https://registry.docker-cn.com"],
  "exec-opts": ["native.cgroupdriver=systemd"]
}

aaa@kylin-pc:~$ sudo systemctl daemon-reload
aaa@kylin-pc:~$ sudo systemctl start docker
aaa@kylin-pc:~$ sudo systemctl enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.

用hello world镜像来测试,

registry.docker-cn.com镜像无效,改用docker.1ms.run仓库可以拉取,输出如下信息, 说明docker安装成功。

复制代码
aaa@kylin-pc:~$ sudo docker pull docker.1ms.run/hello-world
Using default tag: latest
latest: Pulling from hello-world
198f93fd5094: Pull complete 
95ce02e4a4f1: Download complete 
Digest: sha256:ef54e839ef541993b4e87f25e752f7cf4238fa55f017957c2eb44077083d7a6a
Status: Downloaded newer image for docker.1ms.run/hello-world:latest
docker.1ms.run/hello-world:latest

aaa@kylin-pc:~$ sudo docker run docker.1ms.run/hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (arm64v8)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

3.拉取gcc镜像

复制代码
aaa@kylin-pc:~$ sudo docker pull docker.1ms.run/gcc:14.2
14.2: Pulling from gcc
9c242bd2197b: Pull complete 
1a12b4ea7c0c: Pull complete 
280bbe393e78: Pull complete 
1f4f297e4f69: Pull complete 
b58ee5cb7152: Pull complete 
26e4e1e4a57e: Pull complete 
4752dc220c48: Pull complete 
3aaac9860927: Pull complete 
b31dc54c5446: Download complete 
ec72a83a3e14: Download complete 
Digest: sha256:b99b86a28812b1e6453a231a947dc43d76fe192788a12f344a9b568bf9f5d24c
Status: Downloaded newer image for docker.1ms.run/gcc:14.2
docker.1ms.run/gcc:14.2

aaa@kylin-pc:~$ sudo docker run -d -v /home/aaa/par:/par --network host --name gcc142 docker.1ms.run/gcc:14.2
f612cd2cf9c4fcba927e18521668e4cd84dabb8225f166dc6f39896d51b2b131
aaa@kylin-pc:~$ sudo docker exec -it gcc142 bash
Error response from daemon: container f612cd2cf9c4fcba927e18521668e4cd84dabb8225f166dc6f39896d51b2b131 is not running

aaa@kylin-pc:~$ sudo docker logs gcc142
aaa@kylin-pc:~$ sudo docker ps -a
CONTAINER ID   IMAGE                     COMMAND   CREATED         STATUS                     PORTS     NAMES
f612cd2cf9c4   docker.1ms.run/gcc:14.2   "bash"    3 minutes ago   Exited (0) 2 minutes ago             gcc142

aaa@kylin-pc:~$ sudo systemctl status docker

gcc启动失败,日志空白,docker状态中也看不出原因。

而postgres镜像能正常启动

复制代码
aaa@kylin-pc:~$ sudo docker pull docker.1ms.run/postgres
Using default tag: latest
latest: Pulling from postgres
8ef786b18402: Pull complete 
32907a42ce24: Pull complete 
678efd827da7: Pull complete 
00600fe93225: Pull complete 
6cf9a691c71e: Pull complete 
bf8f335dbb73: Pull complete 
11e712b78f59: Pull complete 
52b4ac6b41c6: Pull complete 
8b4769a7dd3c: Pull complete 
0ae13f539d28: Pull complete 
3dca2b464db8: Pull complete 
2d6617baed4d: Pull complete 
3b66ab8c894c: Pull complete 
ba4768def19e: Download complete 
f32c3e47bfcc: Download complete 
Digest: sha256:69e8582b781cb44fa4557b98ed586fe68361e320d9b12f9707494335634f4f3d
Status: Downloaded newer image for docker.1ms.run/postgres:latest
docker.1ms.run/postgres:latest
aaa@kylin-pc:~$ sudo docker run -d -v /home/aaa/par:/par --network host --name pg18 -e POSTGRES_PASSWORD=password docker.1ms.run/postgres
7842681dede783f625d4a51da0ed411609798cdf1237529ae23f7df56a38af73
aaa@kylin-pc:~$ sudo docker exec -it pg18 bash
root@kylin-pc:/# su - postgres
postgres@kylin-pc:~$ psql
psql (18.3 (Debian 18.3-1.pgdg13+1))
Type "help" for help.

postgres=# 

后来想起,以前那台机器的容器是用docker run -itd命令选项运行的,这次没写it,是否这个原因?删除容器重新运行镜像,这次可以了,可能数据库容器可以docker run -d, 而软件不行。

复制代码
aaa@kylin-pc:~$ sudo docker rm gcc142
gcc142
aaa@kylin-pc:~$ sudo docker run -itd -v /home/aaa/par:/par --network host --name gcc142 docker.1ms.run/gcc:14.2
dcbf574ebc6a87cebdce0f53c5424af6bbda7ec98bbf4cdec9951ebeb4fbd3dc
aaa@kylin-pc:~$ sudo docker exec -it gcc142 bash
root@kylin-pc:/# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/aarch64-linux-gnu/14.2.0/lto-wrapper
Target: aarch64-linux-gnu
Configured with: /usr/src/gcc/configure --build=aarch64-linux-gnu --disable-multilib --enable-languages=c,c++,fortran,go
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.0 (GCC) 

接下来编译过程,主要就是3个命令:

复制代码
git clone https://github.com/ggml-org/llama.cpp
太慢出错改用另一个域名
git clone https://bgithub.xyz/ggml-org/llama.cpp
/par/cmake-4.2.3-linux-aarch64/bin/cmake -B build -DBUILD_SHARED_LIBS=OFF
/par/cmake-4.2.3-linux-aarch64/bin/cmake --build build --config Release -j 8

再下载模型试验

复制代码
wget -c https://hf-mirror.com/unsloth/Qwen3.5-9B-GGUF/resolve/main/Qwen3.5-9B-UD-Q4_K_XL.gguf
wget https://hf-mirror.com/unsloth/gemma-3-1b-it-GGUF/resolve/main/gemma-3-1b-it-Q4_K_M.gguf
root@kylin-pc:/par/llama.cpp# build/bin/llama-cli -m /par/Qwen3.5-9B-UD-Q4_K_XL.gguf --ctx-size 16384 -cnv
root@kylin-pc:/# /par/llama.cpp/build/bin/llama-server -m /par/gemma-3-1b-it-Q4_K_M.gguf --jinja -c 0 --host 127.0.0.1 --port 8033

llama-cli和llama-server都能运行,不知为何llama-cli输入汉字就无限滚动,输入英文没事。而官方发布的x64 linux二进制,不存在这个问题。

相关推荐
江湖有缘2 小时前
本地化JSON 处理新方案:基于 Docker的JSON Hero部署全记录
java·docker·json
徐子元竟然被占了!!3 小时前
docker-dockerfile练习
运维·docker·容器
Malone-AI3 小时前
docker换镜像源(docker desktop)
docker·容器
是稻香啊4 小时前
HarmonyOS6 ArkUI 触摸拦截(onTouchIntercept)全面解析与实战演示
ubuntu·华为·harmonyos·harmonyos6
susu10830189114 小时前
Ubuntu 离线环境 安装 Docker Compose
运维·docker·容器
fengyehongWorld5 小时前
docker compose的使用
运维·docker·容器
七夜zippoe5 小时前
Docker容器化实战:核心概念、镜像制作与多阶段构建全解析
java·jvm·数据库·docker·oracle·容器化
是稻香啊5 小时前
HarmonyOS6 ArkUI 子组件触摸测试控制(onChildTouchTest)全面解析与实战演示
华为·harmonyos·harmonyos6
ai产品老杨5 小时前
源码交付破局异构算力:基于GB28181/RTSP与Docker的AI视频平台架构实战
人工智能·docker·音视频