-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 an option to compile libraries statically #424
Comments
Super interested in having this as a compilation option so I can drop my fork and keep using the main one ^_^ |
Why not simply use musl? // Make a static 64 bit binary: docker run --rm=true -itv $PWD:/mnt alpine:3.7 /mnt/build_static.sh // Make a static 32 bit binary: docker run --rm=true -itv $PWD:/mnt i386/alpine:3.7 /mnt/build_static.sh set -ex apk update apk add linux-headers musl-dev gcc go libpcap-dev ca-certificates git mkdir /go export GOPATH=/go mkdir -p /go/src/github.com/yourrepo mkdir -p /mnt/out cp -a /mnt /go/src/github.com/yourrepo/yourtool cd /go/src/github.com/yourrepo/yourtool rm -f yourtool* go get -v ./ ./ go build --ldflags '-linkmode external -extldflags "-static -s -w"' -v ./ cp ./yourtool /mnt/out/ |
@negbie maybe I'm mistaken here, but the problem is not how we build our tool, but how gopacket is built. Given there're no conditional compilation flags (that I'm aware of), the only way to have a static build is to patch |
Hmm ok I thought you just want a binary without external deps(empty ldd output). So that the user doesn't need libpcap installed. |
@negbie yes that is the idea ... I'm not familiar enough with Docker so i'm afraid your instructions are not very clear to me then :) For instance, where does the |
@negbie dude you saved my day! |
Mby I should provide a better explanation. The key here isn't the use of docker, its to circumvent the lack of glibc's static linking by using musl which comes out of the box in alpine linux. So the quickest way is to use the docker alpine container and install there some stuff we need for the static linking. So create a bash script build_static.sh with: #!/bin/sh mkdir /go Inside the same folder run |
@evilsocket so can close the bug? It looks like you can compile it in and this is an alternative solution |
@blshkv Right now I'm using this ... the method mentioned by @negbie doesn't work for every OS as you can see on the build.sh script, but I guess that's not related to this issue. We dropped our fork of gopacket for the time being ... so I guess, yes? ( Needless to say, any suggestion on how to improve that build.sh is more than welcome :P) |
Ok, great! I don't have much time but was happy to help a bit. Thank you all for your work! |
Guys, I have a question. The latest version of bettercap (v2.2) is compiled statically and depends on libpcap for some reason. I actually expected to have an option to compile gopacket with shared libraries (libpcap and pfring) so that bettercap won't require either of them. Is any way to archive this, similar to the usual C programs? |
@blshkv no, 2.2 is not compiled statically on every platform, linux/amd64 build is not static for instance and will require |
sorry, I wasn't clear. bettercap is compiled with gopacket and the outcome is one big binary. Here is the background. At pentoo, we create ebuilds which should list down dependency. I have created a separate ebuild for gopacket which depends on libpcap (and pf_ring optionally). However, it was flagged that bettercap should also depend on libpcap since its binary requires it. I guess there is nothing we can do here. |
there is an issue with bettercap (its binary distribution) and an author decided to fork gopacket in order to compile it with libraries (libpcap in particular) statically.
Perhaps, you could make this option here instead.
For more details, see the following discussion:
bettercap/bettercap#101
The text was updated successfully, but these errors were encountered: