hillu/go-yara

generate a dynamic-link library (.so file)

FinleyTang opened this issue · 1 comments

I want to use go-yara to generate a dynamic-link library (.so file) for easy integration and should be able to run on other Linux machines without the need to install yara. However, I am unsure of how to achieve this.

Firstly, I ran: go build -o libdemo.so -buildmode=c-shared yara.go. While this method successfully generated the .so library, I encountered an error when trying to run it on another machine, which indicated a missing libyara.so.10 dependency
Error: libyara.so.10: cannot open shared object file: No such file or directory

Then, I attempted to include static compilation options by running go build -o libdemo.so -tags yara_static -ldflags="-extldflags='-static' -s -w" -buildmode=c-shared demo.go. However, I encountered the following error message:

/root/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.6.linux-amd64/pkg/tool/linux_amd64/link: running gcc failed: exit status 1 /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/crtbeginT.o: relocation R_X86_64_32 against hidden symbol '__TMC_END__' can not be used when making a shared object /usr/bin/ld: failed to set dynamic section sizes: bad value collect2: error: ld returned 1 exit status

Can someone provide guidance on how to generate a .so file using go-yara and ensure its portability for use on other machines?
c

@FinleyTang Since you seem to have solved the problem for yourself – yould you like to describe what you have been doing?