Can't build "librclone"

What is the problem you are having with rclone?

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.

% head go.mod 
module librclone

go 1.23.3

require (
        bazil.org/fuse v0.0.0-20230120002735-62a210ff1fd5 // indirect
        cloud.google.com/go/auth v0.7.0 // indirect
        cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
        cloud.google.com/go/compute/metadata v0.4.0 // indirect
        github.com/Azure/azure-sdk-for-go/sdk/azcore v1.13.0 // indirect

% head go.sum
bazil.org/fuse v0.0.0-20230120002735-62a210ff1fd5 h1:A0NsYy4lDBZAC6QiYeJ4N+XuHIKBpyhAVRMHRQZKTeQ=
bazil.org/fuse v0.0.0-20230120002735-62a210ff1fd5/go.mod h1:gG3RZAMXCa/OTes6rr9EwusmR1OH1tDDy+cg9c5YliY=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU=
cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY=
cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc=
cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0=
cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To=

The documented one-liner assumes you have git clone'd the rclone repository first, and run the command from the directory you cloned it into.

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.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.