mozillazg / cloud-native-security-with-ebpf

《eBPF 云原生安全:原理与实践》书中示例程序的完整源代码
MIT License
61 stars 7 forks source link

bin/ld: cannot find -lelf: No such file or directory #11

Open gpt8763 opened 2 weeks ago

gpt8763 commented 2 weeks ago

clang的版本如下:centos9 stream操作系统。 clang -v clang version 18.1.8 (CentOS 18.1.8-3.el9) Target: x86_64-redhat-linux-gnu

报如下错误: make[1]: Entering directory '/root/cloud-native-security-with-ebpf/chapter14/modify-incoming-traffic' CC=clang \ CGO_CFLAGS="-I/root/cloud-native-security-with-ebpf/chapter14/modify-incoming-traffic/output" \ CGO_LDFLAGS="-lelf -lz /root/cloud-native-security-with-ebpf/chapter14/modify-incoming-traffic/output/libbpf.a" \ GOARCH=amd64 \ go build \ -tags netgo -ldflags '-w -extldflags "-static"' \ -o main ./main.go

command-line-arguments

/usr/lib/golang/pkg/tool/linux_amd64/link: running clang failed: exit status 1 /opt/rh/gcc-toolset-13/root/usr/lib/gcc/x86_64-redhat-linux/13/../../../../bin/ld: cannot find -lelf: No such file or directory /opt/rh/gcc-toolset-13/root/usr/lib/gcc/x86_64-redhat-linux/13/../../../../bin/ld: cannot find -lz: No such file or directory /opt/rh/gcc-toolset-13/root/usr/lib/gcc/x86_64-redhat-linux/13/../../../../bin/ld: cannot find -lelf: No such file or directory

请问代码是运行在gcc哪一个版本?clang哪个一个版本。centos9安装clang会自动安装gcc-toolset-13.

mozillazg commented 2 weeks ago

@gpt8763 这个错跟 clang 版本没有关系,是缺少一些系统库导致的,centos 系统对应的依赖是:

建议在 ubuntu 22.04 环境中运行示例代码,对应的依赖详见 CI (更新了一下 README,显式提及具体的依赖信息):https://github.com/mozillazg/cloud-native-security-with-ebpf/blob/3bc077f2a2ec6ae67032f9cab0cbd2491eb96ef1/.github/workflows/build.yml#L22