How do I create an OpenGLES2 and GLFW3 snap?

https://askubuntu.com/questions/965455/how-do-i-create-an-opengles2-and-glfw3-snap

I’m having trouble creating a very simple snap. Could anyone help?

@markweston I’d love to help, but I can’t get the thing to build in a clean 16.04 environment. I needed to add gcc to the build-packages (easy) but now I’m getting this:

[...]
Building stopwatch 
make -j8
gcc -o stopwatch -O2 main.c -lGLESv2 -lglfw
main.c: In function ‘main’:
main.c:34:9: warning: implicit declaration of function ‘glfwWaitEventsTimeout’ [-Wimplicit-function-declaration]
         glfwWaitEventsTimeout(1);
         ^
/tmp/cclLGVY4.o: In function `main':
main.c:(.text.startup+0x22d): undefined reference to `glfwWaitEventsTimeout'
collect2: error: ld returned 1 exit status
Makefile:2: recipe for target 'all' failed
make: *** [all] Error 1
Traceback (most recent call last):
  File "/usr/bin/snapcraft", line 9, in <module>
    load_entry_point('snapcraft==2.34', 'console_scripts', 'snapcraft')()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 542, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2569, in load_entry_point
    return ep.load()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2229, in load
    return self.resolve()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2235, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/__main__.py", line 19, in <module>
    run(prog_name='snapcraft')
  File "/usr/lib/python3/dist-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1037, in invoke
    return Command.invoke(self, ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/__init__.py", line 110, in run
    ctx.forward(lifecyclecli.commands['snap'])
  File "/usr/lib/python3/dist-packages/click/core.py", line 552, in forward
    return self.invoke(cmd, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/lifecycle.py", line 132, in snap
    project_options, directory=directory, output=output)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 349, in snap
    execute('prime', project_options)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 130, in execute
    _Executor(config, project_options).run(step, part_names)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 225, in run
    self._run_step(step, part, part_names)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 262, in _run_step
    getattr(part, step)()
  File "/usr/lib/python3/dist-packages/snapcraft/internal/pluginhandler/__init__.py", line 330, in build
    self.plugin.build()
  File "/usr/lib/python3/dist-packages/snapcraft/plugins/make.py", line 128, in build
    self.make()
  File "/usr/lib/python3/dist-packages/snapcraft/plugins/make.py", line 107, in make
    self.run(command + ['-j{}'.format(self.parallel_build_count)], env=env)
  File "/usr/lib/python3/dist-packages/snapcraft/_baseplugin.py", line 202, in run
    return common.run(cmd, cwd=cwd, **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/common.py", line 63, in run
    subprocess.check_call(['/bin/sh', f.name] + cmd, **kwargs)
  File "/usr/lib/python3.5/subprocess.py", line 581, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/bin/sh', '/tmp/tmpxtd0tz4h', 'make', '-j8']' returned non-zero exit status 2

Can you ensure snapcraft cleanbuild works as expected, please?

Can you

sudo snap install snappy-debug

Then before running your application run this on the side

sudo snappy-debug.security scanlog

Some hints should be provided. Most cases, things fail to happen due to missing interfaces https://docs.snapcraft.io/reference/interfaces

1 Like

This requires GLFW >=3.2, (glfwWaitEventsTimeout is a new function in GLFW 3.2) which I suppose is not available on 16.04. I myself built this on 17.04.

I have:

  • Updated the program to use glfwWaitEvents instead of glfwWaitEventsTimeOut so it would work with older GLFW3 which should be available on Ubuntu 16.04
  • Updated snapcraft.yaml to include build-essential build package
  • Pushed the commit so you can try it now

I could not get it to work. It stops when it tries to launch LXD/LXC/whatever that is. Errorlog:

Waiting for a network connection...
Traceback (most recent call last):
  File "/usr/lib/python3.5/urllib/request.py", line 1254, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/usr/lib/python3.5/http/client.py", line 1106, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1151, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.5/http/client.py", line 1102, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
    self.send(msg)
  File "/usr/lib/python3.5/http/client.py", line 877, in send
    self.connect()
  File "/usr/lib/python3.5/http/client.py", line 849, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/lib/python3.5/socket.py", line 693, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.5/socket.py", line 732, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 466, in open
    response = self._open(req, data)
  File "/usr/lib/python3.5/urllib/request.py", line 484, in _open
    '_open', req)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 1282, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.5/urllib/request.py", line 1256, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>
Traceback (most recent call last):
  File "/usr/lib/python3.5/urllib/request.py", line 1254, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/usr/lib/python3.5/http/client.py", line 1106, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1151, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.5/http/client.py", line 1102, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
    self.send(msg)
  File "/usr/lib/python3.5/http/client.py", line 877, in send
    self.connect()
  File "/usr/lib/python3.5/http/client.py", line 849, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/lib/python3.5/socket.py", line 693, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.5/socket.py", line 732, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 466, in open
    response = self._open(req, data)
  File "/usr/lib/python3.5/urllib/request.py", line 484, in _open
    '_open', req)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 1282, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.5/urllib/request.py", line 1256, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>
Traceback (most recent call last):
  File "/usr/lib/python3.5/urllib/request.py", line 1254, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/usr/lib/python3.5/http/client.py", line 1106, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1151, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.5/http/client.py", line 1102, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
    self.send(msg)
  File "/usr/lib/python3.5/http/client.py", line 877, in send
    self.connect()
  File "/usr/lib/python3.5/http/client.py", line 849, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/lib/python3.5/socket.py", line 693, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.5/socket.py", line 732, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 466, in open
    response = self._open(req, data)
  File "/usr/lib/python3.5/urllib/request.py", line 484, in _open
    '_open', req)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 1282, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.5/urllib/request.py", line 1256, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>
Traceback (most recent call last):
  File "/usr/lib/python3.5/urllib/request.py", line 1254, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/usr/lib/python3.5/http/client.py", line 1106, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1151, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.5/http/client.py", line 1102, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
    self.send(msg)
  File "/usr/lib/python3.5/http/client.py", line 877, in send
    self.connect()
  File "/usr/lib/python3.5/http/client.py", line 849, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/lib/python3.5/socket.py", line 693, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.5/socket.py", line 732, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 466, in open
    response = self._open(req, data)
  File "/usr/lib/python3.5/urllib/request.py", line 484, in _open
    '_open', req)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 1282, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.5/urllib/request.py", line 1256, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>

Traceback (most recent call last):
  File "/usr/lib/python3.5/urllib/request.py", line 1254, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/usr/lib/python3.5/http/client.py", line 1106, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1151, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.5/http/client.py", line 1102, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
    self.send(msg)
  File "/usr/lib/python3.5/http/client.py", line 877, in send
    self.connect()
  File "/usr/lib/python3.5/http/client.py", line 849, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/lib/python3.5/socket.py", line 693, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.5/socket.py", line 732, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 466, in open
    response = self._open(req, data)
  File "/usr/lib/python3.5/urllib/request.py", line 484, in _open
    '_open', req)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 1282, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.5/urllib/request.py", line 1256, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>
Stopping local:snapcraft-surely-fresh-corgi
Traceback (most recent call last):
  File "/usr/bin/snapcraft", line 11, in <module>
    load_entry_point('snapcraft==2.34+17.4', 'console_scripts', 'snapcraft')()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 561, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2631, in load_entry_point
    return ep.load()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2291, in load
    return self.resolve()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2297, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/__main__.py", line 19, in <module>
    run(prog_name='snapcraft')
  File "/usr/lib/python3/dist-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/lifecycle.py", line 188, in cleanbuild
    lifecycle.cleanbuild(project_options, remote)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 326, in cleanbuild
    metadata=config.get_metadata(), remote=remote).execute()
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lxd.py", line 147, in execute
    self._wait_for_network()
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lxd.py", line 275, in _wait_for_network
    raise e
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lxd.py", line 270, in _wait_for_network
    self._container_run(['python3', '-c', _NETWORK_PROBE_COMMAND])
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lxd.py", line 113, in _container_run
    check_call(['lxc', 'exec', self._container_name, '--'] + cmd)
  File "/usr/lib/python3.5/subprocess.py", line 271, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['lxc', 'exec', 'local:snapcraft-surely-fresh-corgi', '--', 'python3', '-c', 'import urllib.request; urllib.request.urlopen("http://start.ubuntu.com/connectivity-check.html", timeout=5)']' returned non-zero exit status 1

I have internet connection, I don’t know what happened. Anyway, since as you said it only complained about gcc (which you fixed) and glfwWaitEventsTimeout (which I removed), maybe it will work for you.

I did what you said. Here’s the output:

> sudo snappy-debug.security scanlog
kernel.printk_ratelimit = 0
= AppArmor =
Time: Oct 17 21:06:11
Log: apparmor="ALLOWED" operation="open" profile="snap.stopwatch.stopwatch" name="/sys/devices/pci0000:00/0000:00:02.0/revision" pid=11255 comm="stopwatch" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
File: /sys/devices/pci0000:00/0000:00:02.0/revision (read)
Suggestion:
* adjust program to not access '/sys/devices/pci0000:00/0000:00:02.0/revision'

= AppArmor =
Time: Oct 17 21:06:11
Log: apparmor="ALLOWED" operation="open" profile="snap.stopwatch.stopwatch" name="/sys/devices/pci0000:00/0000:00:02.0/revision" pid=11255 comm="stopwatch" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
File: /sys/devices/pci0000:00/0000:00:02.0/revision (read)
Suggestion:
* adjust program to not access '/sys/devices/pci0000:00/0000:00:02.0/revision'

= AppArmor =
Time: Oct 17 21:06:11
Log: apparmor="ALLOWED" operation="open" profile="snap.stopwatch.stopwatch" name="/sys/devices/pci0000:00/0000:00:02.0/revision" pid=11255 comm="stopwatch" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
File: /sys/devices/pci0000:00/0000:00:02.0/revision (read)
Suggestion:
* adjust program to not access '/sys/devices/pci0000:00/0000:00:02.0/revision'

= AppArmor =
Time: Oct 17 21:06:11
Log: apparmor="ALLOWED" operation="open" profile="snap.stopwatch.stopwatch" name="/sys/devices/pci0000:00/0000:00:02.0/revision" pid=11255 comm="stopwatch" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
File: /sys/devices/pci0000:00/0000:00:02.0/revision (read)
Suggestion:
* adjust program to not access '/sys/devices/pci0000:00/0000:00:02.0/revision'

= AppArmor =
Time: Oct 17 21:06:11
Log: apparmor="ALLOWED" operation="open" profile="snap.stopwatch.stopwatch" name="/sys/devices/pci0000:00/0000:00:02.0/revision" pid=11255 comm="stopwatch" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
File: /sys/devices/pci0000:00/0000:00:02.0/revision (read)
Suggestion:
* adjust program to not access '/sys/devices/pci0000:00/0000:00:02.0/revision'

= AppArmor =
Time: Oct 17 21:06:11
Log: apparmor="ALLOWED" operation="open" profile="snap.stopwatch.stopwatch" name="/sys/devices/pci0000:00/0000:00:02.0/revision" pid=11255 comm="stopwatch" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
File: /sys/devices/pci0000:00/0000:00:02.0/revision (read)
Suggestion:
* adjust program to not access '/sys/devices/pci0000:00/0000:00:02.0/revision'

= AppArmor =
Time: Oct 17 21:06:11
Log: apparmor="ALLOWED" operation="open" profile="snap.stopwatch.stopwatch" name="/sys/devices/pci0000:00/0000:00:02.0/revision" pid=11255 comm="stopwatch" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
File: /sys/devices/pci0000:00/0000:00:02.0/revision (read)
Suggestion:
* adjust program to not access '/sys/devices/pci0000:00/0000:00:02.0/revision'

= AppArmor =
Time: Oct 17 21:06:11
Log: apparmor="ALLOWED" operation="open" profile="snap.stopwatch.stopwatch" name="/sys/devices/pci0000:00/0000:00:02.0/revision" pid=11255 comm="stopwatch" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
File: /sys/devices/pci0000:00/0000:00:02.0/revision (read)
Suggestion:
* adjust program to not access '/sys/devices/pci0000:00/0000:00:02.0/revision'


= AppArmor =
Time: Oct 17 21:14:23
Log: apparmor="DENIED" operation="file_inherit" namespace="root//lxd-snapcraft-surely-fresh-corgi_<var-lib-lxd>" profile="/sbin/dhclient" name="/run/systemd/journal/stdout" pid=11932 comm="dhclient" requested_mask="wr" denied_mask="wr" fsuid=165536 ouid=165536
File: /run/systemd/journal/stdout (write)
Suggestions:
* adjust program to use $SNAP_DATA
* adjust program to use /run/shm/snap.$SNAP_NAME.*

= AppArmor =
Time: Oct 17 21:14:23
Log: apparmor="DENIED" operation="file_inherit" namespace="root//lxd-snapcraft-surely-fresh-corgi_<var-lib-lxd>" profile="/sbin/dhclient" name="/run/systemd/journal/stdout" pid=11932 comm="dhclient" requested_mask="wr" denied_mask="wr" fsuid=165536 ouid=165536
File: /run/systemd/journal/stdout (write)
Suggestions:
* adjust program to use $SNAP_DATA
* adjust program to use /run/shm/snap.$SNAP_NAME.*

That could possibly be the issue. Building snaps on non-xenial is a little wonky because when it runs, it runs against the core snap which, in series 16, is based on Xenial. I suggest building the snap on Xenial.

Ah, you probably need to run sudo lxd init first so it can configure networking.

I tried making a snap with all plugs printed by snap interfaces. That is, I made this:

apps:
    stopwatch:
        command: stopwatch
        plugs: [account-control, alsa, autopilot-introspection, avahi-control, avahi-observe, bluetooth-control, bluez, broadcom-asic-control, browser-support, camera, classic-support, core-support, cups-control, dcdbas-control, desktop, desktop-legacy, docker-support, firewall-control, framebuffer, fuse-support, greengrass-support, gsettings, hardware-observe, hardware-random-control, hardware-random-observe, home, io-ports-control, joystick, kernel-module-control, kubernetes-support, kvm, libvirt, locale-control, log-observe, lxd-support, modem-manager, mount-observe, netlink-audit, netlink-connector, network, network-bind, network-control, network-manager, network-observe, network-setup-control, network-setup-observe, ofono, opengl, openvswitch, openvswitch-support, optical-drive, password-manager-service, physical-memory-control, physical-memory-observe, ppp, process-control, pulseaudio, raw-usb, removable-media, screen-inhibit-control, shutdown, snapd-control, system-observe, system-trace, time-control, timeserver-control, timezone-control, tpm, uhid, unity7, upower-observe, wayland, x11]

It still crashed the same way.

there are no GL drivers or mesa bits included in the core snap, you willl have to add libgl1-mesa-dri to your stage-packages

I did, it didn’t help. While I was struggling with a snap, I made a flatpak which can serve as a reference.

The tree of the flatpak:

.
├── export
├── files
│   ├── bin
│   │   └── stopwatch
│   └── lib
│       ├── libglapi.so -> libglapi.so.0.0.0
│       ├── libglapi.so.0 -> libglapi.so.0.0.0
│       ├── libglapi.so.0.0.0
│       ├── libGLESv2.so -> libGLESv2.so.2.0.0
│       ├── libGLESv2.so.2 -> libGLESv2.so.2.0.0
│       ├── libGLESv2.so.2.0.0
│       ├── libglfw.so -> libglfw.so.3
│       ├── libglfw.so.3 -> libglfw.so.3.2
│       └── libglfw.so.3.2
├── metadata
└── var
    ├── run -> /run
    └── tmp

As you can see, there are three libraries only:

  1. glfw (which is a required as a stage package)
  2. GLESv2 (which is required as a stage package)
  3. glapi (which is a dependency of a libgles2-mesa stage package (checked with apt-cache depends libgles2-mesa))

The flatpak metadata is as follows:

[Application]
name=org.test.stopwatch
runtime=org.freedesktop.Platform/x86_64/1.6
sdk=org.freedesktop.Sdk/x86_64/1.6
command=stopwatch
[Context]
sockets=x11;
devices=dri;

So if we assume that the flatpak is sandboxed as advertised, these three libraries should be enough, because the flatpak is working correctly.

flatpaks are not snaps :wink: they are a delivery mechanism for gui apps on top of a host installation while snaps come as a complete standalone packaging infrastructure.

with snaps you can actually build a whole distro (kernel, bootloader, rootfs and apps (server as well as GUI) on top) and have each of these single bits talk to each other through controlled interfaces, while flatpack assumes an existing GUI installation to hook into.

unlike flatpak a snap runs in context of the core snap by default which is an extremely cut down readonly rootfs (and does not ship mesa drivers). the security confinement setups of both mechanisms differ massively. the flatpak will most likely simply have access to /usr/lib/x86_64-linux-gnu/dri/ of the host OS while the snap does not.

your first log in the askubuntu post indicates that GL can not be initialized because the dri drivers are not accessible, the libgl1-mesa-dri package ships them (and the snap confinement mechanism will allow them to talk to the actual HW via the opengl interface)

Thank you for clarification, I can see how snaps are better and more capable.

build-packages: [build-essential, libglfw3-dev, libgles2-mesa-dev, xserver-xorg-video-all]
stage-packages: [libgl1-mesa-dri, libglfw3, libgles2-mesa, xserver-xorg-video-all]

I have updated the stage-packages as you’ve said, and I even made it built outside of my personal computer, that is, in Ubuntu snap builder to ensure no side-effects: https://build.snapcraft.io/user/Mark-Weston/stopwatch/

It builds, but the errors are the same (and libgl1-mesa-dri is included in the state-packages).

> sudo snap install --edge stop-watch --revision=7 --devmode
> stop-watch
libGL error: unable to load driver: i965_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: i965
libGL error: unable to load driver: i965_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: i965
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
Segmentation fault (core dumped)

does:

find /snap/stop-watch -name i965_dri.so

agree with that ? (the wrapper crated by snapcraft should have added $SNAP/usr/lib/x86_64-linux-gnu/dri to LD_LIBRARY_PATH if everything was set up correctly (and the above find should find the file in that path)

I think it does

> find /snap/stop-watch -name i965_dri.so
/snap/stop-watch/7/usr/lib/x86_64-linux-gnu/dri/i965_dri.so

yeah, that looks fine… does your snap use the desktop launcher (that is responsible for adding the LD_LIBRARY_PATH enhancements for GL, fonts etc) ?

There’s a .desktop file, yes (/var/lib/snapd/desktop/applications/stop-watch_stopwatch.desktop)

[Desktop Entry]
Version=1.0
Type=Application
Name=Stopwatch
GenericName=Stopwatch
Comment=Stopwatch
Exec=stopwatch
Icon=stopwatch
Terminal=False
Categories=Utility;

but I don’t think launched through a desktop launcher because the desktop file is broken. I launch the app directly through command-line either with stop-watch or snap run stop-watch. If you try to launch it with a .desktop file it says it’s broken (which it is): Desktop entry contains no valid Exec line.

Should I fix the desktop file or does it not currently matter? It got broken because when I added it to build.snapcraft.io the stopwatch name was reserved so I had to change it to stop-watch, and naturally some regressions happened.

try adding:

after: [desktop-gtk3]

(or -gtk2 or -qt5 if your app uses either of these instead) underneath your stage-packages line (same indendation) and turn your “command:” into:

command: desktop-launch stopwatch

in the apps: section …