Comments (15)
This is what I did to compile Windows 64-bit libyara.a. I did all compilation in a Ubuntu docker image using MinGW-w64
> docker run -t -i ubuntu:latest /bin/bash
And these are the exact commands I performed.
apt-get update
apt-get install build-essential git
apt-get install gcc-multilib gcc-mingw-w64 autoconf automake libtool libjansson-dev libmagic-dev libssl-dev
git clone --depth=50 https://github.com/VirusTotal/yara.git VirusTotal/yara
export CONFIGFLAGS=--host=x86_64-w64-mingw32
export CC=gcc
cd VirusTotal/yara
./bootstrap.sh
unset CC
./configure $CONFIGFLAGS
make
cd libyara/.libs
file libyara.a
Worked like a charm.... I was able to incorporate this libyara.a into this go-yara project
I had to do one modification and create a cgo_windows.go file with the following CGO instructions. I also copied the .H headers into a new ./include
folder and the windows lib into a new ./lib
folder
// +build windows
package yara
/*
#cgo CFLAGS: -I${SRCDIR}/include
#cgo amd64 LDFLAGS: -L${SRCDIR}/lib -lyara64
#cgo 386 LDFLAGS: -L${SRCDIR}/lib -lyara32
*/
import "C"
...
and modified the old cgo.go file to:
// +build !windows
package yara
/*
#cgo CFLAGS: -I${SRCDIR}/include
#cgo LDFLAGS: -lyara
*/
import "C"
Now I can build from my Sierra macOS both Darwin and Windows executables of my project that is using go-yara package with the following command to target Windows:
CC=/usr/local/Cellar/mingw-w64/4.0.6/bin/x86_64-w64-mingw32-gcc \
LD=/usr/local/Cellar/mingw-w64/4.0.6/bin/x86_64-w64-mingw32-ld \
CGO_ENABLED=1 \
GOOS=windows \
CGO_CFLAGS=-I/usr/local/Cellar/mingw-w64/4.0.6/x86_64-w64-mingw32/include \
CGO_LDFLAGS=-L/usr/local/Cellar/mingw-w64/4.0.6/x86_64-w64-mingw32/lib \
go build --ldflags '-extldflags "-static"' .
And voilà !!! Works like a charm.... I have tested the binary on Windows 10 x64 and works very well... without any dependencies.
It took a while to figure it out. Hopefully this will help other people... Maybe we should move this instructions to the Readme ? Feedback ?
from go-yara.
@chennqqi Neither -I/usr/i686-w64-mingw32/include
nor -L/usr/i686-w64-mingw32/lib
should be necessary, the MinGW compiler includes those search paths by default.
from go-yara.
Both msys and msys2 work correctly.
Compile libyara by mingw-gcc.
from go-yara.
@mcastilho So you are still using the libyara32 and libyara64 generated through the VS project? Do you think that it would make sense to add a build tag, say vs
?
#cgo windows,vs,i386 LDFLAGS: -lyara32
#cgo windows,vs,amd64 LDFLAGS: -lyara64
from go-yara.
No. I am not using the VIsual studio output. I don't think is compatible. I am using the binaries produced by the compilation under Ubunto using MingGW
from go-yara.
In that case, the resulting libraries should simply have the name libyara.a
(without a 32
or 64
prefix), shouldn't they? Unless you have renamed them, of course.
from go-yara.
Yes. I did rename them
from go-yara.
Would you mind looking at my updated build/install instructions and tell me if they work for you?
from go-yara.
@mcastilho I did that under windows and linux.
- build static libyara and install to a
libyara_path
sudo yum install mingw32-gcc
./configure --build=i686-w64-mingw32 --without-crypto --disable-shared --disable-dependency-tracking --disable-magic --disable-cuckoo --without-crypto
make && sudo make install prefix=/usr/i686-w64-mingw32/
` - build go-yara and link
libyara_path
i386-windows:
CC=i686-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=386 CGO_CFLAGS=-I/usr/i686-w64-mingw32/include CGO_LDFLAGS='-L/usr/i686-w64-mingw32/lib -lyara' go install --ldflags '-extldflags "-static"' github.com/hillu/go-yara
x64-linux:
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CGO_CFLAGS=-I/usr/include CGO_LDFLAGS='-L/opt/x86_64/lib -lyara -lm' go install --ldflags '-extldflags "-static"' github.com/hillu/go-yara
- build your app with link
libyara_path
x64-linux:
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CGO_LDFLAGS='-L/opt/x86_64/lib -L/usr/lib64' go build --ldflags '-s -w -extldflags "-static -lm"' YOURAPPPATH
...other environment.
May this help you. Happy chinese new year!
from go-yara.
I got error when I built go-yara:
could not determine kind of name for C.ERROR_INSUFICIENT MEMORY
I tried building with all of instructions, in all cases - this error. Tried on Debian and Ubuntu - same thing.
go version - 1.8
=============== [SOLVED] ====================
just correct in error.go: C.ERROR_INSUFICIENT_MEMORY to C.ERROR_INSUFFICIENT MEMORY ))) just add "F" letter
from go-yara.
oh, awesome, Fixing typos in YARA after 3.5 breaks the API...
from go-yara.
Closing the issue since everything discussed here has been resolved.
from go-yara.
x86_64-w64-mingw32-gcc
This is what I did to compile Windows 64-bit libyara.a. I did all compilation in a Ubuntu docker image using MinGW-w64
> docker run -t -i ubuntu:latest /bin/bash
And these are the exact commands I performed.
apt-get update apt-get install build-essential git apt-get install gcc-multilib gcc-mingw-w64 autoconf automake libtool libjansson-dev libmagic-dev libssl-dev git clone --depth=50 https://github.com/VirusTotal/yara.git VirusTotal/yara export CONFIGFLAGS=--host=x86_64-w64-mingw32 export CC=gcc cd VirusTotal/yara ./bootstrap.sh unset CC ./configure $CONFIGFLAGS make cd libyara/.libs file libyara.a
Worked like a charm.... I was able to incorporate this libyara.a into this go-yara project
I had to do one modification and create a cgo_windows.go file with the following CGO instructions. I also copied the .H headers into a new
./include
folder and the windows lib into a new./lib
folder// +build windows package yara /* #cgo CFLAGS: -I${SRCDIR}/include #cgo amd64 LDFLAGS: -L${SRCDIR}/lib -lyara64 #cgo 386 LDFLAGS: -L${SRCDIR}/lib -lyara32 */ import "C" ...
and modified the old cgo.go file to:
// +build !windows package yara /* #cgo CFLAGS: -I${SRCDIR}/include #cgo LDFLAGS: -lyara */ import "C"
Now I can build from my Sierra macOS both Darwin and Windows executables of my project that is using go-yara package with the following command to target Windows:
CC=/usr/local/Cellar/mingw-w64/4.0.6/bin/x86_64-w64-mingw32-gcc \ LD=/usr/local/Cellar/mingw-w64/4.0.6/bin/x86_64-w64-mingw32-ld \ CGO_ENABLED=1 \ GOOS=windows \ CGO_CFLAGS=-I/usr/local/Cellar/mingw-w64/4.0.6/x86_64-w64-mingw32/include \ CGO_LDFLAGS=-L/usr/local/Cellar/mingw-w64/4.0.6/x86_64-w64-mingw32/lib \ go build --ldflags '-extldflags "-static"' .
And voilà !!! Works like a charm.... I have tested the binary on Windows 10 x64 and works very well... without any dependencies.
It took a while to figure it out. Hopefully this will help other people... Maybe we should move this instructions to the Readme ? Feedback ?
I followed the above steps, but returned the error " /usr/bin/x86_64-w64-mingw32-ld: unable to find - lyara64 ". Could you help me solve it ?
from go-yara.
@Jacob-Dong The error
/usr/bin/x86_64-w64-mingw32-ld: unable to find - lyara64
tells you that the linker that is invoked for linking the final program or library does not find libyate64.a
, libyara64.so
or libyara64.dll
in the search path for libraries (parameter -L
, usually specified via LDFLAGS
environment variable.)
If you built YARA from sources, it's most likely that libyara.a
and libyara.so.*
was generated, so the -lyara64
parameter would be wrong.
from go-yara.
lls you that the linker that is invoked for linking the final program or library does not find
libyate64.a
,libyara64.so
orlibyara64.dll
in the search path for libraries (parameter-L
, usually specified viaLDFLAGS
environment variable.)If you built YARA from sources, it's most likely that
libyara.a
andlibyara.so.*
was generated, so the
Thanks for answering. Actually as you said, so I modified the " -lyara64 " of cgo_windows.go to "-lyara", then the error disappered.
from go-yara.
Related Issues (20)
- ld: warning: directory not found for option '-L/usr/local/Cellar/yara/4.1.2/lib' HOT 1
- "invalid pointer on stack" panic HOT 5
- Is there a code sample or a tutorial for beginners somewhere? HOT 6
- Error when compiling go-yara HOT 4
- The problem of scanning the file with Chinese filename HOT 14
- using go-yara with my own compiled yara library without crypto HOT 3
- cannot convert file.Fd() (value of type uintptr) to type _Ctype_HANDLE HOT 14
- Module Install fails b/c pkg-config cannot find libcrypto which is needed by yara HOT 3
- Yara getting "lost" during file/process scanning HOT 4
- static build failed: undefined reference to `log2'
- Compiling the Windows 32-bit DLL using Visual C++ HOT 1
- 4.3.0 fails to cross compile on mingw
- Documentation Is Not Clear HOT 3
- There's no way to return an error from MemoryBlockIterator HOT 5
- yr_scanner_scan_file Using mmap is a dangerous operation HOT 9
- WASM support HOT 1
- windows goland support? HOT 3
- Shippable binary for OSX HOT 6
- Can‘t build yara module statically into executable HOT 2
- cbPool storage exhausted HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-yara.