Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wayland build: Could NOT find OpenGL (missing: GLX) #2019

Closed
JonasVautherin opened this issue Jan 15, 2024 · 12 comments
Closed

Wayland build: Could NOT find OpenGL (missing: GLX) #2019

JonasVautherin opened this issue Jan 15, 2024 · 12 comments
Labels
bug Something isn't working build Related to build, configuration or CI/CD linux

Comments

@JonasVautherin
Copy link
Collaborator

Note: opening an issue here under the advice of @louwers on Slack, hoping to get insights from @jwinarske.

Trying to build maplibre-native on Wayland, I get the following error in the CMake configuration step:

CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find OpenGL (missing: GLX)

I am running on Alpine 3.19 with Wayland.

I saw this issue and tried different things to remove the need for GLX (my understanding being that I don't need GLX on Wayland), like this:

cmake -DMBGL_WITH_EGL=ON -DMLN_WITH_WAYLAND=ON -DMLN_WITH_ELG=ON -DMBGL_WITH_WAYLAND=ON -Bbuild -S.

But it does not change the GLX error I get. Am I missing something to build with Wayland?

@JonasVautherin JonasVautherin added the bug Something isn't working label Jan 15, 2024
@acalcutt
Copy link
Collaborator

acalcutt commented Jan 15, 2024

If you are doing this on a headless system, maybe throwing 'xvfb-run --auto-servernum' before the command will allow it to work? I've never had to use that on cmake, but it usually helps with GLX errors on headless linux systems.

Also, Is this node binaries that you are building? I'd check out the node workflow steps at
https://github.com/maplibre/maplibre-native/blob/main/.github/workflows/node-ci.yml#L206-L216
and
https://github.com/maplibre/maplibre-native/blob/main/.github/workflows/node-ci.yml#L236-L243

Node needs the DMLN_WITH_NODE=ON now, which you would then add the DMLN_WITH_EGL=ON to have it build in egl mode. I'm not familiar with that DMLN_WITH_WAYLAND flag.

@acalcutt
Copy link
Collaborator

acalcutt commented Jan 15, 2024

I remember seeing this old conversation that makes me think xvfb is needed with EGL on headless systems
#217 (comment)

Btw, I just noticed you have a typo. the option is DMLN_WITH_EGL , not DMLN_WITH_ELG

@louwers louwers added linux build Related to build, configuration or CI/CD labels Jan 15, 2024
@JonasVautherin
Copy link
Collaborator Author

JonasVautherin commented Jan 15, 2024

Thanks for the quick answer!

If you are doing this on a headless system

No, that's my main Desktop machine 🙈.

Btw, I just noticed you have a typo. the option is DMLN_WITH_EGL , not DMLN_WITH_ELG

🤦‍♂️ you are right, and this one actually makes a difference, though it still gives an error for OpenGL (not sure if it fails earlier or later, though):

CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find OpenGL (missing: OPENGL_opengl_LIBRARY)

Let me see how far as go with that new error!

@acalcutt
Copy link
Collaborator

I'd still give xvfb a try even if you aren't on a headless system. with non-egl node binaries, i have seen cases where the users video card driver does not support opengl, and gets opengl related errors. xvfb should allow it to emulate opengl if that was the case.

@JonasVautherin
Copy link
Collaborator Author

Right, let me try. Also I am not building for node. I want to build C++ for Linux (so I'm running CMake from the root CMakeLists.txt, I assumed that was correct 🤔) and then for Android. I would like to contribute to Android, but I think I need to compile the C++ for that 👍.

@acalcutt
Copy link
Collaborator

acalcutt commented Jan 15, 2024

If you aren't building node I would assume you would just omit the DMLN_WITH_NODE=ON , should pretty much be the same build commands. I'm not familiar with wayland, but usually follow these instructions for linux ( https://github.com/maplibre/maplibre-native/tree/main/platform/linux#build ). Node is pretty much the same linux c++ build but adds a few binaries.

I was thinking another thing you could try is if the opengl-2 branch behave differently. The opengl level has been raised in main, so maybe that branch would build differently?

@JonasVautherin
Copy link
Collaborator Author

JonasVautherin commented Jan 15, 2024

Hmm it seems like OPENGL_opengl_LIBRARY requires libglvnd, which depends on libx11, glproto and libxext. I don't find libglvnd for Alpine, and I don't have X11 🤔.

but usually follow these instructions for linux

They actually don't say much other than "use CMake" 🙈. Which is fine, it's probably just that I have an unusual system and I haven't found yet how to build for it. It feels like it should be possible given the other GitHub issues about Wayland.

I was thinking another thing you could try is if the opengl-2 branch behave differently.

Same issue there.

Now I wonder if I need to install X11 compatibility stuff for Wayland, or if I am missing an option. I currently try with -DMLN_WITH_EGL=ON -DMLN_WITH_NODE=OFF -DMLN_WITH_WAYLAND=ON.

@JonasVautherin
Copy link
Collaborator Author

In the CMake module, it adds the OPENGL_opengl_LIBRARY component under those conditions:

  # now we append the libraries as appropriate.  The complicated logic
  # basically comes down to "use libOpenGL when we can, and add in specific
  # context mechanisms when requested, or we need them to preserve the previous
  # default where glx is always available."
  if((NOT OPENGL_USE_EGL AND
      NOT OPENGL_opengl_LIBRARY AND
          OPENGL_glx_LIBRARY AND
      NOT OPENGL_gl_LIBRARY) OR
     (NOT OPENGL_USE_EGL AND
      NOT OPENGL_USE_GLES3 AND
      NOT OPENGL_USE_GLES2 AND
      NOT OPENGL_glx_LIBRARY AND
      NOT OPENGL_gl_LIBRARY) OR
     (NOT OPENGL_USE_EGL AND
          OPENGL_opengl_LIBRARY AND
          OPENGL_glx_LIBRARY) OR
     (NOT OPENGL_USE_GLES3 AND
      NOT OPENGL_USE_GLES2 AND
          OPENGL_USE_EGL))
    list(APPEND _OpenGL_REQUIRED_VARS OPENGL_opengl_LIBRARY)
  endif()

Because I set -DMLN_WITH_EGL=ON, it gets here:

    find_package(OpenGL REQUIRED EGL)

And this fails to find OPENGL_opengl_LIBRARY, which I don't have because (I believe) it is an X11 thing. So I tried with -DOPENGL_USE_GLES3 (which required me to apk add glfw-dev), and I go further:

-- Found OpenGL: /usr/lib/libEGL.so  found components: EGL 
-- Looking for strerror_r
-- Looking for strerror_r - not found
-- Found OpenGL: /usr/lib/libEGL.so   
-- Checking for one of the modules 'glfw3'
-- Configuring done (1.1s)
CMake Error at vendor/benchmark.cmake:5 (add_library):
  Cannot find source file:

    /tmp/maplibre-native/vendor/benchmark/src/sleep.cc

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm
  .ccm .cxxm .c++m .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90
  .f95 .f03 .hip .ispc
Call Stack (most recent call first):
  benchmark/CMakeLists.txt:27 (include)


CMake Error at vendor/benchmark.cmake:5 (add_library):
  No SOURCES given to target: mbgl-vendor-benchmark
Call Stack (most recent call first):
  benchmark/CMakeLists.txt:27 (include)

Feels like progress 🙈.

@jwinarske
Copy link
Contributor

I haven't read through entirely, but something to keep in mind is the wayland support is intended to be mutually exclusive with x11/xcb. Opposed to being additive. So you would need to disable all the x11/xcb support. I can take a look tomorrow

@JonasVautherin
Copy link
Collaborator Author

JonasVautherin commented Jan 15, 2024

I managed to pass the configure step with:

cmake -DMLN_WITH_EGL=ON -DMLN_WITH_NODE=OFF -DMLN_WITH_WAYLAND=ON -DOPENGL_USE_GLES3=ON -Bbuild -S.

I really wonder if the CMakeLists should not set OPENGL_USE_GLES2 for Linux whenever MLN_WITH_EGL=ON and MLN_WITH_WAYLAND=ON 🤔. Because given the CMake module listed above, enabling OPENGL_USE_EGL but not OPENGL_USE_GLES2 (or OPENGL_USE_GLES3, but using OPENGL_USE_GLES2 seems to find my version 3 on my system) will always set OPENGL_opengl_LIBRARY, which is X11. At least that's my understanding, what do you think?

I worked around the last error (about the path to sleep.cc being wrong) by commenting out benchmarks (EDIT: my bad, it was a submodule issue).

It is now building 🤞.

@JonasVautherin
Copy link
Collaborator Author

I got it to build! I'll close this issue and will follow-up with a small PR meant to start a discussion about how the CMake configuration could be improved for Wayland.

Thanks all for the help!

@acalcutt
Copy link
Collaborator

acalcutt commented Jan 16, 2024

I worked around the last error (about the path to sleep.cc being wrong) by commenting out benchmarks (EDIT: my bad, it was a submodule issue).

I wonder if you add -DCMAKE_BUILD_TYPE=Release to your options if it would skip building those lines you had to comment out. I know it builds more in debug mode.

Edit: nevermind, i missed the comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working build Related to build, configuration or CI/CD linux
Projects
None yet
Development

No branches or pull requests

4 participants