Fyne: Dynamic library dependency issue

Created on 17 Nov 2020  路  10Comments  路  Source: fyne-io/fyne

Describe the bug:

When building Hello World app on Ubuntu 20.04 I got this error message:

# github.com/go-gl/glfw/v3.3/glfw
/usr/bin/ld: cannot find -lXxf86vm
collect2: error: ld returned 1 exit status

I managed to work-around this issue by doing this:

sudo apt install libxxf86vm-dev

To Reproduce:

Steps to reproduce the behaviour:

  1. Follow steps in https://www.youtube.com/watch?v=-v1vz_NcWng
  2. go run main.go
  3. Crash

Example code:

package main

import (
    "fyne.io/fyne/app"
    "fyne.io/fyne/widget"
)

func main() {
    a := app.New()
    w := a.NewWindow("hello")
    w.SetContent(widget.NewLabel("Hello World!"))
    w.ShowAndRun()
}

Device (please complete the following information):

  • OS: Ubuntu (linux/amd64)
  • Version: 20.04 (up-to-date as of 2020-11-17)
  • Go version: 1.13.8
  • Fyne version: [e.g. 1.2.0 or git SHA]
Linux question

All 10 comments

That should have been installed by the apt-get install command that is listed at https://developer.fyne.io/started/.
This is just a development dependency and is not required by the users of your app.

Thank you for your response.

I used this command line to install fyne:

go get fyne.io/fyne

Is that not supposed to be sufficient?

The command you post prepares the library, however if you don't have developer tools installed it can fail to compile.
On most operating systems that should work out of the box, but Linux is a little complicated and needs the developer libraries installed as listed in the documentation.

This is due to the way that Linux development is split into many different packages, on some distributions (such as Ubuntu) the presence of a graphics driver does not ensure the development libraries to go with it. From our doc on the "Linux" tab at the page I posted above:

You will need to install Go, gcc and the graphics library header files using your package manager

Thanks again for pointing me in right direction.

Could you elaborate on this one:

"This is just a development dependency and is not required by the users of your app."

If I distribute the binary "hello" would others not need to install development dependencies? If the answer is yes, why did I have to install them when running hello?

If I distribute the binary "hello" would others not need to install development dependencies?

Yes this is exactly correct.
The reason you need development dependencies to run the hello world is because the "go get" command is building it from source. Distributed apps will typically be compiled and packaged, meaning no need for go tools or dependencies.

Ok, is there a go command to make the distributable version of hello binary then?

go build will build a binary file you can share.
If you want to package a full desktop app with metadata etc then fyne package is your friend, see https://developer.fyne.io/started/distribution

Just to clarify. The development dependencies are statically linked into the binary. That鈥檚 rather technical, but the consequence is basically that the compiled binary includes the needed dependencies. That is why they are only needed when you are compiling and not when running it 馃檪

@Jacalz thank you for explaining this even clearer. This will help people googling about this behaviour in the future 馃尡

To summarize this for future reference:

  1. -dev packages are needed when using "go run" and "go build" commands, since the static libraries contained in those packages are included in the result application/executable.
  2. Therefore, running the resulting application/executable on another machine does not require those libraries or dev packages.

FYI - the resulting application/executable was 17 mb on my machine, and it was possible to run it even after sudo apt-get remove libgl1-mesa-dev xorg-dev, as expected. I also found the "upx-ucl" utility for Ubuntu to compress the binary, so it is now down to 9 mb. Nice!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Nigh picture Nigh  路  5Comments

lusingander picture lusingander  路  3Comments

Geo25rey picture Geo25rey  路  7Comments

codenoid picture codenoid  路  4Comments

pbarnum picture pbarnum  路  6Comments