First of all I don't understand much of Go and I'm not familiar with the build system. I'm just following the suggestions of the compiler.
I'm trying to build librclone so I can use the python bindings. I'm following the instructions listed in the github readme
I'm using Ubuntu 22.04.4 LTS and Go version go1.21.3 linux/amd64
The command you were trying to run (eg rclone copy /tmp remote:tmp)
I'm just copy/pasting the command from the Readme.
go build --buildmode=c-shared -o librclone.so github.com/rclone/rclone/librclone
However Go outputs the following error
no required module provides package github.com/rclone/rclone/librclone: go.mod file not found in current directory or any parent directory; see 'go help modules'
Since the compiler was complaining about module I tried:
go get github.com/rclone/rclone/librclone
which outputted the following:
go: go.mod file not found in current directory or any parent directory.
'go get' is no longer supported outside a module.
To build and install a command, use 'go install' with a version,
like 'go install example.com/cmd@latest'
For more information, see https://golang.org/doc/go-get-install-deprecation
or run 'go help get' or 'go help install'.
then I tried (not working without @latest)
go install github.com/rclone/rclone/librclone@latest
and command completes without errors. It actually creates a bin file: /home/user/go/bin/librclone
It makes me think the build way has something to do with this module system deprecation. Or perhaps I'm missing a step?
GoLang has changed a little, so I tried the following, which basically creates a dummy go.mod file. That should be all that's needed
% mkdir X
% cd X
% go mod init librclone
go: creating new go.mod: module librclone
% cat go.mod
module librclone
go 1.23.3
% go build --buildmode=c-shared -o librclone.so github.com/rclone/rclone/librclone
no required module provides package github.com/rclone/rclone/librclone; to add it:
go get github.com/rclone/rclone/librclone
OK, so I ran that go get command and it downloaded a lot of stuff (all those dependencies!! 373 downloads!!)
And now..
% go build --buildmode=c-shared -o librclone.so github.com/rclone/rclone/librclone
% ls
go.mod go.sum librclone.h librclone.so
% file librclone.so
librclone.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=6ae0b70993240fb1dc03493bdf75ba0d0e0d6463, not stripped
If you now look at go.mod you'll see all the dependencies and versions it downloaded.
Thank you both! I have now compiled it successfully.
The problem was a mix of two things:
I haven'd cloned the whole project. I assumed that I don't need to, since the build command included a link to github. Again, I'm not a Go expert so I really don't know how the build should work, hence my confusion.
the default go package on Ubuntu has messed up Go structure and I got various missing GOROOT errors for few packages of the project.
I removed the default Go from Ubuntu and downloaded the latest binaries from go.dev website and the build command executed successfully from the root of the rclone project.