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

Cross compilation on macOS #9

Closed
dreadl0ck opened this issue Dec 27, 2018 · 3 comments
Closed

Cross compilation on macOS #9

dreadl0ck opened this issue Dec 27, 2018 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@dreadl0ck
Copy link
Owner

Cross compiling from macOS to linux and windows fails for me, due to gopackets libpcap bindings.
Maybe @notti can help?

Compile for Windows:

# install compiler toolchain and libpcap headers
$ brew install mingw-w64
$ brew install libpcap

$ GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 CGO_CFLAGS="-I/usr/local/opt/libpcap/include" go build -o netcap-windows -i github.com/dreadl0ck/netcap/cmd
# github.com/google/gopacket/pcap
/usr/local/Cellar/mingw-w64/5.0.4_1/toolchain-x86_64/bin/x86_64-w64-mingw32-ld: cannot find -lwpcap
collect2: error: ld returned 1 exit status

Compile for Linux:

$ GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -o netcap-linux -i github.com/dreadl0ck/netcap/cmd
# github.com/dreadl0ck/netcap/cmd
/usr/local/Cellar/go/1.11.4/libexec/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: warning: ignoring file /var/folders/3n/1r2xxfv55d35jxh33rklbzm80000gn/T/go-link-877356077/go.o, file was built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture being linked (x86_64): /var/folders/3n/1r2xxfv55d35jxh33rklbzm80000gn/T/go-link-877356077/go.o
Undefined symbols for architecture x86_64:
"__cgo_topofstack", referenced from:
    __cgo_f163a891a53f_Cfunc_calloc in 000001.o
    __cgo_f163a891a53f_Cfunc_pcap_activate in 000001.o
    __cgo_f163a891a53f_Cfunc_pcap_can_set_rfmon in 000001.o
    __cgo_f163a891a53f_Cfunc_pcap_compile in 000001.o
    __cgo_f163a891a53f_Cfunc_pcap_create in 000001.o
    __cgo_f163a891a53f_Cfunc_pcap_datalink in 000001.o
    __cgo_f163a891a53f_Cfunc_pcap_datalink_name_to_val in 000001.o
    ...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
@dreadl0ck dreadl0ck added the help wanted Extra attention is needed label Dec 27, 2018
@notti
Copy link

notti commented Jan 3, 2019

Sorry for the late reply, but I was on winter holiday.
Hmm I don't have experience with cross-compiling cgo stuff. But I suspect one problem here will be the lines: https://github.com/google/gopacket/blob/6d81e5661bc8ae1efe3fbd78bd790daef871b489/pcap/pcap.go#L18-L20
For windows you would need the sdk for winpcap and then add the correct path to the ldflags.
With google/gopacket#568 you wouldn't need cgo for windows.
Not sure how to do the crosscompiling for linux. Maybe use travis-ci for building the linux-version?

@dreadl0ck
Copy link
Owner Author

Thanks for the pointers!
Will try again using your non cgo windows contribution :)

@dreadl0ck
Copy link
Owner Author

Thanks to google/gopacket#568 from @notti the windows cross compilation compilation works fine now :)

Linux cross compilation still gives me the same errors,
if anyone has an Idea let me know please.

Meanwhile binaries for Linux are compiled in a docker container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
2 participants