Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gpt8763 opened this issue Oct 19, 2024 · 1 comment
Open

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

gpt8763 opened this issue Oct 19, 2024 · 1 comment

Comments

@gpt8763
Copy link

gpt8763 commented Oct 19, 2024

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
Copy link
Owner

mozillazg commented Oct 20, 2024

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

  • cannot find -lz: No such file or directory -> zlib-devel
  • cannot find -lelf: No such file or directory -> elfutils-libelf-devel

建议在 ubuntu 22.04 环境中运行示例代码,对应的依赖详见 CI (更新了一下 README,显式提及具体的依赖信息):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants