Hi, i am trying to build a dynamic library to be able to call it from c++/c#
I am using the restic/builder:latest and invoking it using: docker run --rm --volume “$PWD/restic-0.9.5:/restic” --volume “$PWD/output:/output” restic/builder
Now I changed the file: helpers/build-release-binaries/main.go to add the build mode: -buildmode=c-shared but am getting an error about missing gcc:
$sudo docker run --rm --volume "$PWD/restic-0.9.5:/restic" --volume "$PWD/output:/output" restic/builder
building with 8 workers
# github.com/restic/restic/cmd/restic
loadinternal: cannot find runtime/cgo
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exec: "gcc": executable file not found in $PATH
I’m a newbie to golang, but from what i read about it, it seems that only build type “exe” is supported without external linker. So my question is: is it somehow possible to change the build environment to build a library out of restic?
From that error it looks like that gcc is not installed. Maybe you should create a new docker image from the existing one and install gcc in it ? I never did it, but that’s what I would try.
Thank you both for your replies. Well it was and was not in missing gcc.
In the end I ended up building a simple vagrant box with the tools as mentioned in reproducible builds docu.
Once i got that, after some searching I managed to compile restic as a static library (with go 1.13) using:
Compile it with: g++ -o test -I . -L . test.cpp -lrestic_amd64 -lpthread -m64
You can then run it like this:
vagrant@ubuntu-bionic:~/work/linux-example$ ./test version
restic 0.9.5-dev (compiled manually) compiled with go1.13 on linux/amd64
vagrant@ubuntu-bionic:~/work/linux-example$
It’s been a while i touched c/c++ and am a complete golang newbie so bear with me
I’m trying now to build a windows .dll and use it from managed code (seems to be a bigger beast )
Hi @umbro, I am also working on build a dynamic library of restic. I want to see your work but I can’t open the link of restic.patch and test.cpp. Can you post them again, thank you!
If it is interesting for you, one goal in rustic is to separate the CLI from a library which contains basically all functionality to work with a restic repo.
I have to admit that so far I didn’t do much to extract things into a library, but if you know Rust or want to learn it, feel free to work on it an propose a PR!