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

make build error #316

Closed
summerzhou2011 opened this issue Oct 26, 2023 · 6 comments
Closed

make build error #316

summerzhou2011 opened this issue Oct 26, 2023 · 6 comments

Comments

@summerzhou2011
Copy link

we need setup test environment on bare metal machine not on docker.
environment
''' [root@localhost ebpf_exporter]# go version

go version go1.21.2 linux/amd64

[root@localhost ebpf_exporter]# uname -a

Linux localhost.localdomain 5.15.0-101.103.2.1.el9uek.x86_64 #2 SMP Tue May 2 01:10:45 PDT 2023 x86_64 x86_64 x86_64 GNU/Linux

[root@localhost ebpf_exporter]#

'''

build static
the error

'''
[root@localhost ebpf_exporter]# make build

make build-binary GO_LDFLAGS='-extldflags "-static"'

make[1]: Entering directory '/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter'

go build -o ebpf_exporter -v -ldflags="-extldflags "-static" -X github.com/prometheus/common/version.Version=v2.2.0-90-g96fe799 -X github.com/prometheus/common/version.Branch=master -X github.com/prometheus/common/version.Revision=96fe799 -X github.com/prometheus/common/version.BuildUser=[email protected] -X github.com/prometheus/common/version.BuildDate=2023-10-26T19:52:49+08:00" ./cmd/ebpf_exporter

github.com/cloudflare/ebpf_exporter/v2/cmd/ebpf_exporter

github.com/cloudflare/ebpf_exporter/v2/cmd/ebpf_exporter

/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1

/usr/bin/ld: cannot find -lelf

/usr/bin/ld: cannot find -lz

/usr/bin/ld: cannot find -lelf

/usr/bin/ld: cannot find -lz

/usr/bin/ld: cannot find -lelf

/usr/bin/ld: cannot find -lz

/usr/bin/ld: cannot find -lelf

/usr/bin/ld: cannot find -lz

/usr/bin/ld: cannot find -lelf

/usr/bin/ld: cannot find -lz

/usr/bin/ld: cannot find -lelf

/usr/bin/ld: cannot find -lz

/usr/bin/ld: cannot find -lelf

/usr/bin/ld: cannot find -lz

/usr/bin/ld: cannot find -lresolv

/usr/bin/ld: cannot find -lc

collect2: error: ld returned 1 exit status

make[1]: *** [Makefile:65: build-binary] Error 1

make[1]: Leaving directory '/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter'

make: *** [Makefile:57: build-static] Error 2

[root@localhost ebpf_exporter]# locate libz.so

/usr/lib/libz.so

/usr/lib64/libz.so

/usr/lib64/libz.so.1

/usr/lib64/libz.so.1.2.11

[root@localhost ebpf_exporter]# locate libelf.so

/usr/lib64/libelf.so

/usr/lib64/libelf.so.1

[root@localhost ebpf_exporter]# locate libresolv.so

/usr/lib64/libresolv.so

/usr/lib64/libresolv.so.2

[root@localhost ebpf_exporter]#

'''

build dynamic and run ebpf_exporter
the error
'''
[root@localhost ebpf_exporter]# make build-dynamic

make build-binary

make[1]: Entering directory '/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter'

go build -o ebpf_exporter -v -ldflags=" -X github.com/prometheus/common/version.Version=v2.2.0-90-g96fe799 -X github.com/prometheus/common/version.Branch=master -X github.com/prometheus/common/version.Revision=96fe799 -X github.com/prometheus/common/version.BuildUser=[email protected] -X github.com/prometheus/common/version.BuildDate=2023-10-26T19:54:31+08:00" ./cmd/ebpf_exporter

github.com/cloudflare/ebpf_exporter/v2/cmd/ebpf_exporter

make[1]: Leaving directory '/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter'

[root@localhost ebpf_exporter]# ./ebpf_exporter --config.dir=examples --config.names=biolatency

./ebpf_exporter: /usr/lib64/libbpf.so.1: version `LIBBPF_1.2.0' not found (required by ./ebpf_exporter)

[root@localhost ebpf_exporter]#

'''

@summerzhou2011
Copy link
Author

we need setup test environment on bare metal machine not on docker.
environment

 [root@localhost ebpf_exporter]# go version

go version go1.21.2 linux/amd64

[root@localhost ebpf_exporter]# uname -a

Linux localhost.localdomain 5.15.0-101.103.2.1.el9uek.x86_64 https://github.com/cloudflare/ebpf_exporter/pull/2 SMP Tue May 2 01:10:45 PDT 2023 x86_64 x86_64 x86_64 GNU/Linux

[root@localhost ebpf_exporter]#

'''

build static
the error

'''
[root@localhost ebpf_exporter]# make build

make build-binary GO_LDFLAGS='-extldflags "-static"'

make[1]: Entering directory '/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter'

go build -o ebpf_exporter -v -ldflags="-extldflags "-static" -X github.com/prometheus/common/version.Version=v2.2.0-90-g96fe799 -X github.com/prometheus/common/version.Branch=master -X github.com/prometheus/common/version.Revision=96fe799 -X github.com/prometheus/common/version.BuildUser=[[email protected]](mailto:[email protected]) -X github.com/prometheus/common/version.BuildDate=2023-10-26T19:52:49+08:00" ./cmd/ebpf_exporter

github.com/cloudflare/ebpf_exporter/v2/cmd/ebpf_exporter

github.com/cloudflare/ebpf_exporter/v2/cmd/ebpf_exporter
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1

/usr/bin/ld: cannot find -lelf

/usr/bin/ld: cannot find -lz

/usr/bin/ld: cannot find -lelf

/usr/bin/ld: cannot find -lz

/usr/bin/ld: cannot find -lelf

/usr/bin/ld: cannot find -lz

/usr/bin/ld: cannot find -lelf

/usr/bin/ld: cannot find -lz

/usr/bin/ld: cannot find -lelf

/usr/bin/ld: cannot find -lz

/usr/bin/ld: cannot find -lelf

/usr/bin/ld: cannot find -lz

/usr/bin/ld: cannot find -lelf

/usr/bin/ld: cannot find -lz

/usr/bin/ld: cannot find -lresolv

/usr/bin/ld: cannot find -lc

collect2: error: ld returned 1 exit status

make[1]: *** [Makefile:65: build-binary] Error 1

make[1]: Leaving directory '/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter'

make: *** [Makefile:57: build-static] Error 2

[root@localhost ebpf_exporter]# locate libz.so

/usr/lib/libz.so

/usr/lib64/libz.so

/usr/lib64/libz.so.1

/usr/lib64/libz.so.1.2.11

[root@localhost ebpf_exporter]# locate libelf.so

/usr/lib64/libelf.so

/usr/lib64/libelf.so.1

[root@localhost ebpf_exporter]# locate libresolv.so

/usr/lib64/libresolv.so

/usr/lib64/libresolv.so.2

[root@localhost ebpf_exporter]#

build dynamic and run ebpf_exporter
the error

[root@localhost ebpf_exporter]# make build-dynamic

make build-binary

make[1]: Entering directory '/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter'

go build -o ebpf_exporter -v -ldflags=" -X github.com/prometheus/common/version.Version=v2.2.0-90-g96fe799 -X github.com/prometheus/common/version.Branch=master -X github.com/prometheus/common/version.Revision=96fe799 -X github.com/prometheus/common/version.BuildUser=[[email protected]](mailto:[email protected]) -X github.com/prometheus/common/version.BuildDate=2023-10-26T19:54:31+08:00" ./cmd/ebpf_exporter

github.com/cloudflare/ebpf_exporter/v2/cmd/ebpf_exporter

make[1]: Leaving directory '/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter'

[root@localhost ebpf_exporter]# ./ebpf_exporter --config.dir=examples --config.names=biolatency

./ebpf_exporter: /usr/lib64/libbpf.so.1: version `LIBBPF_1.2.0' not found (required by ./ebpf_exporter)

[root@localhost ebpf_exporter]#

@summerzhou2011
Copy link
Author

root@localhost ebpf_exporter]# locate libbpf.so

/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter/libbpf/dest/usr/lib/libbpf.so

/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter/libbpf/dest/usr/lib/libbpf.so.1

/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter/libbpf/dest/usr/lib/libbpf.so.1.2.2

/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter/libbpf/src/libbpf.so

/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter/libbpf/src/libbpf.so.1

/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter/libbpf/src/libbpf.so.1.2.2

/usr/lib64/libbpf.so.1

/usr/lib64/libbpf.so.1.0.0

[root@localhost ebpf_exporter]# 

@summerzhou2011
Copy link
Author

using system provided libbpf

[root@localhost ebpf_exporter]# export BUILD_LIBBPF=0

[root@localhost ebpf_exporter]# make build      

make build-binary GO_LDFLAGS='-extldflags "-static"'

make[1]: Entering directory '/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter'

go build -o ebpf_exporter -v -ldflags="-extldflags "-static" -X github.com/prometheus/common/version.Version=v2.2.0-90-g96fe799 -X github.com/prometheus/common/version.Branch=master -X github.com/prometheus/common/version.Revision=96fe799 -X github.com/prometheus/common/[email protected] -X github.com/prometheus/common/version.BuildDate=2023-10-26T19:58:59+08:00" ./cmd/ebpf_exporter

github.com/aquasecurity/libbpfgo

# github.com/aquasecurity/libbpfgo

In file included from /root/go/pkg/mod/github.com/aquasecurity/[email protected]/btf.go:5:

./libbpfgo.h:17:10: fatal error: bpf/bpf.h: No such file or directory

   17 | #include <bpf/bpf.h>

      |          ^~~~~~~~~~~

compilation terminated.

make[1]: *** [Makefile:65: build-binary] Error 1

make[1]: Leaving directory '/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter'

make: *** [Makefile:57: build-static] Error 2

[root@localhost ebpf_exporter]# 

[root@localhost ebpf_exporter]# 

[root@localhost ebpf_exporter]# make build-dynamic

make build-binary

make[1]: Entering directory '/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter'

go build -o ebpf_exporter -v -ldflags=" -X github.com/prometheus/common/version.Version=v2.2.0-90-g96fe799 -X github.com/prometheus/common/version.Branch=master -X github.com/prometheus/common/version.Revision=96fe799 -X github.com/prometheus/common/[email protected] -X github.com/prometheus/common/version.BuildDate=2023-10-26T19:59:12+08:00" ./cmd/ebpf_exporter

github.com/aquasecurity/libbpfgo

# github.com/aquasecurity/libbpfgo

In file included from /root/go/pkg/mod/github.com/aquasecurity/[email protected]/btf.go:5:

./libbpfgo.h:17:10: fatal error: bpf/bpf.h: No such file or directory

   17 | #include <bpf/bpf.h>

      |          ^~~~~~~~~~~

compilation terminated.

make[1]: *** [Makefile:65: build-binary] Error 1

make[1]: Leaving directory '/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter'

make: *** [Makefile:61: build-dynamic] Error 2

[root@localhost ebpf_exporter]# 

@bobrik
Copy link
Contributor

bobrik commented Oct 27, 2023

The answer is the same as with the previous issue: you need static libraries if you want to build a static binary.

Your system libbpf is too old to build a dynamically linked binary.

@summerzhou2011
Copy link
Author

when I build dynamic not using libbpf system provided, the error

[root@localhost ebpf_exporter]# make build-dynamic

make build-binary

make[1]: Entering directory '/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter'

go build -o ebpf_exporter -v -ldflags=" -X github.com/prometheus/common/version.Version=v2.2.0-90-g96fe799 -X github.com/prometheus/common/version.Branch=master -X github.com/prometheus/common/version.Revision=96fe799 -X github.com/prometheus/common/version.BuildUser=[[email protected]](mailto:[email protected]) -X github.com/prometheus/common/version.BuildDate=2023-10-26T19:54:31+08:00" ./cmd/ebpf_exporter

github.com/cloudflare/ebpf_exporter/v2/cmd/ebpf_exporter

make[1]: Leaving directory '/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter'

[root@localhost ebpf_exporter]# ./ebpf_exporter --config.dir=examples --config.names=biolatency

./ebpf_exporter: /usr/lib64/libbpf.so.1: version `LIBBPF_1.2.0' not found (required by ./ebpf_exporter)

[root@localhost ebpf_exporter]#

root@localhost ebpf_exporter]# locate libbpf.so

/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter/libbpf/dest/usr/lib/libbpf.so

/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter/libbpf/dest/usr/lib/libbpf.so.1

/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter/libbpf/dest/usr/lib/libbpf.so.1.2.2

/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter/libbpf/src/libbpf.so

/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter/libbpf/src/libbpf.so.1

/root/go/src/github.com/cloudflare/ebpf_exporter/ebpf_exporter/libbpf/src/libbpf.so.1.2.2

/usr/lib64/libbpf.so.1

/usr/lib64/libbpf.so.1.0.0

[root@localhost ebpf_exporter]# 

@bobrik
Copy link
Contributor

bobrik commented Oct 31, 2023

You are using system libbpf at runtime when you do this, and it's not new enough.

@bobrik bobrik closed this as completed Nov 14, 2023
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