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

makefile: used CC=$(CROSS_COMPILE)gcc for CGO compile. #519

Merged
merged 3 commits into from
Apr 12, 2024

Conversation

cfc4n
Copy link
Member

@cfc4n cfc4n commented Apr 12, 2024

Fix bug that prevents compiling jschwinger233/elibpcap package during cross-compilation.

arm64 ubuntu 22.04

/home/cfc4n/project/ecapture $ CROSS_ARCH=amd64 make
make[1]: Leaving directory '/home/cfc4n/project/ecapture/lib/libpcap'
CGO_CFLAGS='-O2 -g -gdwarf-4 -I/home/cfc4n/project/ecapture/lib/libpcap/' CGO_LDFLAGS='-O2 -g -L/home/cfc4n/project/ecapture/lib/libpcap/ -lpcap -static' GOOS=linux GOARCH=amd64 CC=clang go build -tags linux -ldflags "-w -s -X 'ecapture/cli/cmd.GitVersion=linux_amd64:0.7.5-20240303-bfb4a8c:[CORE]' -X 'main.enableCORE=true' " -o bin/ecapture
file bin/ecapture
# github.com/jschwinger233/elibpcap
../../go/pkg/mod/github.com/jschwinger233/elibpcap@v0.0.0-20231010035657-e99300096f5e/elibpcap.go:25:22: undefined: CompileEbpf
bin/ecapture: cannot open `bin/ecapture' (No such file or directory)

Fixed

/home/cfc4n/project/ecapture $ CROSS_ARCH=amd64 make
make[1]: Leaving directory '/home/cfc4n/project/ecapture/lib/libpcap'
CGO_ENABLED=1 CGO_CFLAGS='-O2 -g -gdwarf-4 -I/home/cfc4n/project/ecapture/lib/libpcap/' CGO_LDFLAGS='-O2 -g -L/home/cfc4n/project/ecapture/lib/libpcap/ -lpcap -static' GOOS=linux GOARCH=amd64 CC=x86_64-linux-gnu-gcc go build -tags linux -ldflags "-w -s -X 'ecapture/cli/cmd.GitVersion=linux_amd64:0.7.5-20240303-bfb4a8c:[CORE]' -X 'main.enableCORE=true' -linkmode=external -extldflags -static " -o bin/ecapture
file bin/ecapture
# ecapture
/usr/lib/gcc-cross/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/bin/ld: /tmp/go-link-3421481706/000004.o: in function `_cgo_9c8efe9babca_C2func_getaddrinfo':
/tmp/go-build/cgo-gcc-prolog:58: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc-cross/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/bin/ld: /home/cfc4n/project/ecapture/lib/libpcap//libpcap.a(nametoaddr.o): in function `pcap_nametoaddr':
/home/cfc4n/project/ecapture/lib/libpcap/./nametoaddr.c:181: warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc-cross/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/bin/ld: /home/cfc4n/project/ecapture/lib/libpcap//libpcap.a(nametoaddr.o): in function `pcap_nametonetaddr':
/home/cfc4n/project/ecapture/lib/libpcap/./nametoaddr.c:270: warning: Using 'getnetbyname_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc-cross/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/bin/ld: /home/cfc4n/project/ecapture/lib/libpcap//libpcap.a(nametoaddr.o): in function `pcap_nametoproto':
/home/cfc4n/project/ecapture/lib/libpcap/./nametoaddr.c:527: warning: Using 'getprotobyname_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
bin/ecapture: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=048ccf5df926a5aabc7f99c59b33867063b9a2ca, for GNU/Linux 3.2.0, stripped
Fri Apr 12 16:28:59 UTC 2024

Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
@cfc4n cfc4n added the fix bug fix PR label Apr 12, 2024
Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
@cfc4n cfc4n merged commit a8156b6 into master Apr 12, 2024
5 checks passed
@cfc4n cfc4n deleted the cross-compile-core-ebpf-fix branch April 12, 2024 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix bug fix PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant