Skip to content
This repository has been archived by the owner on Feb 7, 2022. It is now read-only.

gopacket cross-compiling with xgo #65

Open
SergiiShapoval opened this issue Nov 14, 2016 · 12 comments
Open

gopacket cross-compiling with xgo #65

SergiiShapoval opened this issue Nov 14, 2016 · 12 comments

Comments

@SergiiShapoval
Copy link

Hi,
I am using https://godoc.org/github.com/google/gopacket that depends on libpcap-devel library.
How can I pass this dependency to xgo container with deps tag?
I wasn't able to find tar for libpcap-devel only rpm - https://www.rpmfind.net/linux/rpm2html/search.php?query=libpcap

For windows artifact, I guess, I will need to pass another library (Winpcap). Am I right?

@SergiiShapoval SergiiShapoval changed the title gopacket libs cross-compiling with xgo gopacket cross-compiling with xgo Nov 14, 2016
@vyrus001
Copy link

I have a similar issue with OpenCV => https://github.com/lazywei/go-opencv/

the dependency can be installed via apt on Debian, linked manually against DLLs on windows, and added via homebrew on OSX. but manually adding the source tarball and all of the underlying dependencies is frankly, a nasty experience. (it also requires cmake to build, so, insert issue with adding deps that require cmake).

I suppose a simple way to address this might be to either modify my xgo docker image manually and doing and installing the library, (of course this would create problems when compiling multi platform without careful design). Or perhaps adding the ability to run a set of commands before the compile process starts ( as suggested in another issue i believe). But ultimately I am unsure of what would be the "best" approach to adding this functionality idiomatically to the xgo project.

@SergiiShapoval
Copy link
Author

Hi, thank you for response,
currently, we eliminated functionality which is working with gopacket only
for Linux, other platforms don't have such capabilities. It was done by
changing source code in a build process.

2016-11-16 23:01 GMT+02:00 vyrus001 notifications@github.com:

I have a similar issue with OpenCV => https://github.com/lazywei/go-
opencv/

the dependency can be installed via apt on Debian, linked manually against
DLLs on windows, and added via homebrew on OSX. but manually adding the
source tarball and all of the underlying dependencies is frankly, a nasty
experience. (it also requires cmake to build, so, insert issue with adding
deps that require cmake).

I suppose a simple way to address this might be to either modify my xgo
docker image manually and doing and installing the library, (of course this
would create problems when compiling multi platform without careful
design). Or perhaps adding the ability to run a set of commands before the
compile process starts ( as suggested in another issue i believe). But
ultimately I am unsure of what would be the "best" approach to adding this
functionality idiomatically to the xgo project.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#65 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AITR3UJTXtyBVOYecDyWMJljydDY7Q96ks5q-28QgaJpZM4KxF6X
.

@ykyuen
Copy link

ykyuen commented Oct 21, 2017

Hi @SergiiShapoval,

i am facing the same problem becoz the xgo container is missing the pcap.h.

vendor/github.com/tsg/gopacket/pcap/pcap.go:20:18: fatal error: pcap.h: No such file or directory

i try to build the image be specifying the --deps flag

xgo --deps=http://www.tcpdump.org/release/libpcap-1.8.1.tar.gz ...

but it gives another error

Bootstrapping linux/arm-5...
Compiling for linux/arm-5...
Configuring dependency libpcap-1.8.1 for arm-linux-gnueabi...
configure: error: pcap type not determined when cross-compiling; use --with-pcap=...
2017/10/21 17:51:53 Failed to cross compile package: exit status 1.

actually i just need to build my project for linux. how could u make the the gopacket works for linux build?

@SergiiShapoval
Copy link
Author

Hi @ykyuen,
we are currently removing gopacket for windows and iOS, only build it for linux in our build process

@ykyuen
Copy link

ykyuen commented Oct 23, 2017

Hi @SergiiShapoval,

Thanks for your quick reply.

i couldn't get the build work for linux because the pcap.h is missing in the xgo-base image. Currently i forked the repository and install the libpcap package.

https://github.com/ykyuen/xgo/blob/f837a51ebcf5eca5ce824712ff1bbb3acda35900/docker/base/Dockerfile#L39

but this only works for linux/amd64 target. for 386 and arm architectures, they threw another error.

/usr/bin/ld: cannot find -lpcap

@SergiiShapoval
Copy link
Author

@ykyuen we are using linux/amd64, haven't tried others...

@ykyuen
Copy link

ykyuen commented Oct 24, 2017

@SergiiShapoval
got it~ thx for your info~ =)

@negbie
Copy link

negbie commented Jan 9, 2018

Any news about including libpcap? Tried ykyuen fork and it worked!

@evilsocket
Copy link

Same problem as @ykyuen:

$ xgo --deps=http://www.tcpdump.org/release/libpcap-1.8.1.tar.gz github.com/evilsocket/bettercap-ng

Checking docker installation...
Client:
 Version:      1.13.1
 API version:  1.26
 Go version:   go1.8.3
 Git commit:   092cba3
 Built:        Thu Oct 12 22:34:44 2017
 OS/Arch:      linux/amd64

Server:
 Version:      1.13.1
 API version:  1.26 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   092cba3
 Built:        Thu Oct 12 22:34:44 2017
 OS/Arch:      linux/amd64
 Experimental: false

Checking for required docker image karalabe/xgo-latest... found.
Downloading new dependency: http://www.tcpdump.org/release/libpcap-1.8.1.tar.gz...
New dependency cached: /home/evilsocket/.xgo-cache/libpcap-1.8.1.tar.gz.
Cross compiling github.com/evilsocket/bettercap-ng...
Fetching main repository github.com/evilsocket/bettercap-ng...
github.com/evilsocket/bettercap-ng (download)
github.com/chzyer/readline (download)
github.com/dustin/go-humanize (download)
github.com/google/gopacket (download)
github.com/mdlayher/dhcp6 (download)
github.com/elazarl/goproxy (download)
github.com/gin-gonic/gin (download)
github.com/gin-contrib/sse (download)
github.com/golang/protobuf (download)
github.com/ugorji/go (download)
Fetching https://gopkg.in/go-playground/validator.v8?go-get=1
Parsing meta tags from https://gopkg.in/go-playground/validator.v8?go-get=1 (status code 200)
get "gopkg.in/go-playground/validator.v8": found meta tag get.metaImport{Prefix:"gopkg.in/go-playground/validator.v8", VCS:"git", RepoRoot:"https://gopkg.in/go-playground/validator.v8"} at https://gopkg.in/go-playground/validator.v8?go-get=1
gopkg.in/go-playground/validator.v8 (download)
Fetching https://gopkg.in/yaml.v2?go-get=1
Parsing meta tags from https://gopkg.in/yaml.v2?go-get=1 (status code 200)
get "gopkg.in/yaml.v2": found meta tag get.metaImport{Prefix:"gopkg.in/yaml.v2", VCS:"git", RepoRoot:"https://gopkg.in/yaml.v2"} at https://gopkg.in/yaml.v2?go-get=1
gopkg.in/yaml.v2 (download)
github.com/mattn/go-isatty (download)
github.com/inconshreveable/go-vhost (download)
github.com/malfunkt/iprange (download)
github.com/pkg/errors (download)
github.com/olekukonko/tablewriter (download)
github.com/mattn/go-runewidth (download)
github.com/robertkrimen/otto (download)
Fetching https://gopkg.in/sourcemap.v1?go-get=1
Parsing meta tags from https://gopkg.in/sourcemap.v1?go-get=1 (status code 200)
get "gopkg.in/sourcemap.v1": found meta tag get.metaImport{Prefix:"gopkg.in/sourcemap.v1", VCS:"git", RepoRoot:"https://gopkg.in/sourcemap.v1"} at https://gopkg.in/sourcemap.v1?go-get=1
gopkg.in/sourcemap.v1 (download)
Fetching https://gopkg.in/unrolled/secure.v1?go-get=1
Parsing meta tags from https://gopkg.in/unrolled/secure.v1?go-get=1 (status code 200)
get "gopkg.in/unrolled/secure.v1": found meta tag get.metaImport{Prefix:"gopkg.in/unrolled/secure.v1", VCS:"git", RepoRoot:"https://gopkg.in/unrolled/secure.v1"} at https://gopkg.in/unrolled/secure.v1?go-get=1
gopkg.in/unrolled/secure.v1 (download)
Assembling toolchain for android-16/arm...
Bootstrapping android-16/arm...
Compiling for android-16/arm...
Configuring dependency libpcap-1.8.1 for arm-linux-androideabi...
configure: error: pcap type not determined when cross-compiling; use --with-pcap=...
2018/02/05 20:42:32 Failed to cross compile package: exit status 1.

Any update?

@negbie
Copy link

negbie commented Feb 7, 2018

@evilsocket did you try @ykyuen fork https://github.com/ykyuen/xgo ?
He added libpcap0.8-dev into the base image
ykyuen@eabf78e

With his fork I was able to cross compile for mips64

./xgo -ldflags='-linkmode external -extldflags "-static -s -w"' --deps=http://www.tcpdump.org/release/libpcap-1.8.1.tar.gz --depsargs=--with-pcap=linux --targets=linux/mips64 github.com/google/gopacket

@evilsocket
Copy link

OMG will try ASAP, thanks so much!

@ItsFunny
Copy link

ItsFunny commented Jan 5, 2019

i cant do this ,i tried cross compile my project which used the gopacket to windows ,command like this

xgo -ldflags='-linkmode external -extldflags "-static -s -w"' --deps=https://www.winpcap.org/install/bin/WpcapSrc_4_1_3.zip --depsargs=--with-pcap=windows --targets=windows/* ./tProejct

of course i forked the ykyuen

but it turns out no such file pcap.h ,

its that ok to use .zip and is it ok to change 'with-pcap=linux' to 'windows'

i dont know ,someone give me a hand plz :(

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

No branches or pull requests

6 participants