0

I've already reviewed the answers at usr/bin/ld: cannot find -l<nameOfTheLibrary> and none of them work for this context.

I just got a new laptop and setting up Go. A simple hello world program works, but when I try a more complicated program, I get:

go run .
# runtime/cgo
/usr/bin/ld: cannot find -lavcodec
/usr/bin/ld: cannot find -lavformat
/usr/bin/ld: cannot find -lavutil
/usr/bin/ld: cannot find -lswscale
/usr/bin/ld: cannot find -lswresample
/usr/bin/ld: cannot find -lavdevice
/usr/bin/ld: cannot find -lavfilter
collect2: error: ld returned 1 exit status

I'm not sure where in my program the error occurs because the above is the only output I get.

$ gcc --version
gcc (Ubuntu 10.3.0-1ubuntu1) 10.3.0

EDIT: Here's a small sample that reproduces the error:

package main

import "net/http"

func main() {
    cli := &http.Client{}
    rsp, err := cli.Get("https://google.com")
    if err != nil {
        panic(err)
    }

    defer rsp.Body.Close()

}

This is a brand new Go install on a brand new Ubuntu 21.04 install:

Go version: go version go1.16.8 linux/amd64

Output of go env:

$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/home/bob/go/bin"
GOCACHE="/home/bob/.cache/go-build"
GOENV="/home/bob/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/bob/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/bob/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org"
GOROOT="/snap/go/8408"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/snap/go/8408/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.8"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/bob/Desktop/projects/go.mod"
CGO_CFLAGS="-I/home/bob/ffmpeg/include"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-L/home/bob/ffmpeg/lib/ -lavcodec -lavformat -lavutil -lswscale -lswresample -lavdevice -lavfilter"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2239100166=/tmp/go-build -gno-record-gcc-switches"
Nothingbetter
  • 48
  • 2
  • 14

1 Answers1

5

Flag -l is used to indicate libraries that the linker is supposed to use to build your application. If it's a new laptop, it's possible that the libraries are not installed. You should be able to install the libraries needed using the following commands:

sudo apt-get update -y
sudo apt-get install -y libavfilter-dev
sudo apt-get install -y libavcodec-dev
sudo apt-get install -y libavutil-dev
sudo apt-get install -y libswscale-dev
sudo apt-get install -y libswresample-dev
sudo apt-get install -y libavdevice-dev
sudo apt-get install -y libavfilter-dev
Jonathon S.
  • 1,928
  • 1
  • 12
  • 18