botherder / kraken

Cross-platform Yara scanner written in Go
GNU General Public License v3.0
330 stars 43 forks source link

Building 64bit Windows binary #3

Closed botherder closed 3 years ago

botherder commented 5 years ago

Currently building 64bit Windows binary raises some issues with architecture differences with Go's linker.

$GOPATH/pkg/tool/linux_amd64/link: running x86_64-w64-mingw32-gcc failed: exit status 1
/usr/bin/x86_64-w64-mingw32-ld: i386 architecture of input file `/tmp/go-link-888075984/000000.o' is incompatible with i386:x86-64 output
collect2: error: ld returned 1 exit status

Need to find the appropriate procedure to build 64bit successfully.

hillu commented 3 years ago

The object files that were produced by the Go compiler (e.g. /tmp/go-link-888075984/000000.o) are for i386 and can't be linked with external objects and libraries that have been built for x86-64. You need to build both YARA and the Go bits for the same architecture: This is done for YARA by selecting the right compiler and passing the right prefix to configure --host=…. And it is done for the Go code by setting both GOOS and GOARCH.

32bit: --host=i686-w64-mingw32 CC=i686-w64-mingw32-gcc GOOS=windows GOARCH=386 64bit: --host=x86_64-w64-mingw32 CC=x86_64-w64-mingw32-gcc GOOS=windows`GOARCH=amd64

hillu commented 3 years ago

I have some suggestions on how to improve the Makefile (and cut down the necessary build instructions in the process). Are you interested in a PR?

botherder commented 3 years ago

@hillu Yes of course! That'd be greatly appreciated.