CMake: Fails to link libwx_gtk3u_gl, EGL functions not found (Windows) (Issue #23673)

101 views
Skip to first unread message

Carlo Bramini

unread,
Jun 30, 2023, 6:12:19 AM6/30/23
to wx-...@googlegroups.com, Subscribed
<!--

Please describe exactly how you build wxWidgets, including the full `configure`
command line and/or `make` command line if relevant.

Please attach the full build log, but feel free to quote the relevant parts of
it here.

When using `configure`, please also attach `config.log` file.

-->

### Description
I unpacked the sources of wxWidgets-3.2.2.1 and configured them with CMake, path to sources and `-G Ninja` as generator.
Configuration completed without troubles.
Then, I called `ninja` for building the libraries.
Unfortuantely, the linking of the last object failed with these messages:

```
$ ninja
[1/1] Linking CXX shared library lib/libwx_gtk3u_gl-3.2-0.dll
FAILED: lib/libwx_gtk3u_gl-3.2-0.dll lib/libwx_gtk3u_gl-3.2.dll.a
: && /usr/bin/c++.exe -g -pthread -shared -Wl,--enable-auto-import -o lib/libwx_gtk3u_gl-3.2-0.dll -Wl,--out-implib,lib/libwx_gtk3u_gl-3.2.dll.a -Wl,--major-image-version,0,--minor-image-version,2 libs/gl/CMakeFiles/wxgl.dir/__/__/__/__/src/common/glcmn.cpp.o libs/gl/CMakeFiles/wxgl.dir/__/__/__/__/src/gtk/glcanvas.cpp.o libs/gl/CMakeFiles/wxgl.dir/__/__/__/__/src/unix/glx11.cpp.o libs/gl/CMakeFiles/wxgl.dir/__/__/__/__/src/unix/glegl.cpp.o -L/usr/lib/w32api -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lcairo-gobject -lpango-1.0 -lgdk_pixbuf-2.0 -lcairo -lglib-2.0 -lintl -lgobject-2.0 /usr/lib/libSM.dll.a /usr/lib/libICE.dll.a /usr/lib/libX11.dll.a /usr/lib/libXext.dll.a /usr/lib/libXtst.dll.a /usr/lib/libgnomevfs-2.dll.a /usr/lib/libgspell-1.dll.a lib/libwx_gtk3u_core-3.2.dll.a /usr/lib/libGLU.dll.a /usr/lib/libGL.dll.a /usr/lib/libGL.dll.a /usr/lib/libGLU.dll.a -lgtk-3 -lgdk-3 -latk-1.0 lib/libwx_baseu-3.2.dll.a -L/usr/lib/w32api /usr/lib/libSDL2main.a /usr/lib/libSDL2.dll.a -lnotify -lgio-2.0 -lpangocairo-1.0 -lcairo-gobject -lpango-1.0 -lgdk_pixbuf-2.0 -lcairo -lglib-2.0 -lintl -lgobject-2.0 /usr/lib/libSM.dll.a /usr/lib/libICE.dll.a /usr/lib/libX11.dll.a /usr/lib/libXext.dll.a /usr/lib/libXtst.dll.a /usr/lib/libgnomevfs-2.dll.a /usr/lib/libgspell-1.dll.a && :
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: libs/gl/CMakeFiles/wxgl.dir/__/__/__/__/src/unix/glegl.cpp.o: in function `wxGLContext::wxGLContext(wxGLCanvas*, wxGLContext const*, wxGLContextAttrs const*)':
/wxWidgets/wxWidgets3.2-3.2.2.1-1.x86_64/src/wxWidgets-3.2.2.1/src/unix/glegl.cpp:313: undefined reference to `eglCreateContext'
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: libs/gl/CMakeFiles/wxgl.dir/__/__/__/__/src/unix/glegl.cpp.o: in function `wxGLContext::~wxGLContext()':
/wxWidgets/wxWidgets3.2-3.2.2.1-1.x86_64/src/wxWidgets-3.2.2.1/src/unix/glegl.cpp:328: undefined reference to `eglGetCurrentContext'
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /wxWidgets/wxWidgets3.2-3.2.2.1-1.x86_64/src/wxWidgets-3.2.2.1/src/unix/glegl.cpp:329: undefined reference to `eglMakeCurrent'
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /wxWidgets/wxWidgets3.2-3.2.2.1-1.x86_64/src/wxWidgets-3.2.2.1/src/unix/glegl.cpp:332: undefined reference to `eglDestroyContext'
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: libs/gl/CMakeFiles/wxgl.dir/__/__/__/__/src/unix/glegl.cpp.o: in function `wxGLContext::SetCurrent(wxGLCanvas const&) const':
/wxWidgets/wxWidgets3.2-3.2.2.1-1.x86_64/src/wxWidgets-3.2.2.1/src/unix/glegl.cpp:340: undefined reference to `eglMakeCurrent'
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: libs/gl/CMakeFiles/wxgl.dir/__/__/__/__/src/unix/glegl.cpp.o: in function `wxGLCanvasEGL::GetDisplay()':
/wxWidgets/wxWidgets3.2-3.2.2.1-1.x86_64/src/wxWidgets-3.2.2.1/src/unix/glegl.cpp:394: undefined reference to `eglGetPlatformDisplay'
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: libs/gl/CMakeFiles/wxgl.dir/__/__/__/__/src/unix/glegl.cpp.o: in function `wxGLCanvasEGL::CreateSurface()':
/wxWidgets/wxWidgets3.2-3.2.2.1-1.x86_64/src/wxWidgets-3.2.2.1/src/unix/glegl.cpp:478: undefined reference to `eglCreatePlatformWindowSurface'
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: libs/gl/CMakeFiles/wxgl.dir/__/__/__/__/src/unix/glegl.cpp.o: in function `wxGLCanvasEGL::~wxGLCanvasEGL()':
/wxWidgets/wxWidgets3.2-3.2.2.1-1.x86_64/src/wxWidgets-3.2.2.1/src/unix/glegl.cpp:534: undefined reference to `eglDestroySurface'
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: libs/gl/CMakeFiles/wxgl.dir/__/__/__/__/src/unix/glegl.cpp.o: in function `wxGLCanvasBase::IsExtensionSupported(char const*)':
/wxWidgets/wxWidgets3.2-3.2.2.1-1.x86_64/src/wxWidgets-3.2.2.1/src/unix/glegl.cpp:550: undefined reference to `eglGetDisplay'
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /wxWidgets/wxWidgets3.2-3.2.2.1-1.x86_64/src/wxWidgets-3.2.2.1/src/unix/glegl.cpp:552: undefined reference to `eglQueryString'
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: libs/gl/CMakeFiles/wxgl.dir/__/__/__/__/src/unix/glegl.cpp.o: in function `wxGLCanvasEGL::InitConfig(wxGLAttributes const&)':
/wxWidgets/wxWidgets3.2-3.2.2.1-1.x86_64/src/wxWidgets-3.2.2.1/src/unix/glegl.cpp:571: undefined reference to `eglInitialize'
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /wxWidgets/wxWidgets3.2-3.2.2.1-1.x86_64/src/wxWidgets-3.2.2.1/src/unix/glegl.cpp:576: undefined reference to `eglBindAPI'
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /wxWidgets/wxWidgets3.2-3.2.2.1-1.x86_64/src/wxWidgets-3.2.2.1/src/unix/glegl.cpp:584: undefined reference to `eglChooseConfig'
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: libs/gl/CMakeFiles/wxgl.dir/__/__/__/__/src/unix/glegl.cpp.o: in function `wxGLCanvasEGL::SwapBuffers()':
/wxWidgets/wxWidgets3.2-3.2.2.1-1.x86_64/src/wxWidgets-3.2.2.1/src/unix/glegl.cpp:650: undefined reference to `eglSwapBuffers'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
```

It looks like that this step fails because libEGL has not been included together with other link libraries.
libEGL is installed and it has been also detected by CMake when configuring.
I hacked a bit the `build.ninja` file, by using `/usr/lib/libEGL.dll.a` (which is the value that I have found into `CMakeCache.txt`) and I added it to `LINK_LIBRARIES` variable for `lib/libwx_gtk3u_gl-3.2-0.dll`.
After that, also this last link completed successfully.
It seems to me that there is a missing reference to libEGL for this target that just needs to be added, perhaps on other platforms it works because libEGL is added because it's a dependency for other libraries used here

VZ

unread,
Jul 2, 2023, 7:49:58 PM7/2/23
to wx-...@googlegroups.com, Subscribed

I don't see anything clearly wrong here, we seem to be adding EGL libraries correctly here:

https://github.com/wxWidgets/wxWidgets/blob/3b236b8ffdeb46e419bdfc5554b6caa080bbabcc/build/cmake/init.cmake#L415-L417

Could you please check the value of OPENGL_egl_LIBRARY in the generated CMakeCache.txt? For me it's set to /usr/lib/x86_64-linux-gnu/libEGL.so and this library is present in the linker command.

Any ideas would be welcome...


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/23673/1617004563@github.com>

Carlo Bramini

unread,
Jul 3, 2023, 10:04:00 AM7/3/23
to wx-...@googlegroups.com, Subscribed

Hello,
I debugged how that code from build/cmake/init.cmake works here:

<============== Enters here!
find_package(OpenGL)
if(OPENGL_FOUND)
    <============== Enters here!
    foreach(gltarget OpenGL::GL OpenGL::GLU OpenGL::OpenGL)
        if(TARGET ${gltarget})
            set(OPENGL_LIBRARIES ${gltarget} ${OPENGL_LIBRARIES})
        endif()
    endforeach()
endif()
if(WXGTK3 AND OpenGL_EGL_FOUND AND wxUSE_GLCANVAS_EGL)
    <============== Enters here!
    if(TARGET OpenGL::EGL)
        <============== DOES NOT enter here!
        set(OPENGL_LIBRARIES OpenGL::EGL ${OPENGL_LIBRARIES})
    endif()
    set(OPENGL_INCLUDE_DIR ${OPENGL_INCLUDE_DIR} ${OPENGL_EGL_INCLUDE_DIRS})
    find_package(WAYLANDEGL)
    if(WAYLANDEGL_FOUND AND wxHAVE_GDK_WAYLAND)
        list(APPEND OPENGL_LIBRARIES ${WAYLANDEGL_LIBRARIES})
    endif()
endif()

Perhaps, it is something that it can happen if libEGL works but it doesn't support OpenGL::EGL because it's old.
What do you think about a change like this one?

if(TARGET OpenGL::EGL)
    set(OPENGL_LIBRARIES OpenGL::EGL ${OPENGL_LIBRARIES})
else()
    set(OPENGL_LIBRARIES ${OPENGL_egl_LIBRARY} ${OPENGL_LIBRARIES})
endif()

The above change allows me to build successfully.
If OpenGL::EGL exists, then ok.
Otherwise, since OpenGL_EGL_FOUND is true, it adds ${OPENGL_egl_LIBRARY} as last resort solution.

This is the content of CMakeCache.txt about that variable:

//Path to a file.
OPENGL_EGL_INCLUDE_DIR:PATH=/usr/include

//Path to a library.
OPENGL_egl_LIBRARY:FILEPATH=/usr/lib/libEGL.dll.a


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/23673/1618363568@github.com>

VZ

unread,
Jul 3, 2023, 10:15:53 AM7/3/23
to wx-...@googlegroups.com, Subscribed

Sorry, I have no idea why wouldn't OpenGL::EGL be set, hopefully @MaartenBent could give his opinion. I'm all for fixing this, but it seems really weird to have 2 different ways of adding a dependent library and while I wish I could explain it as just yet another CMake weirdness, I have a feeling that it might be rather due to my own ignorance and not a problem with CMake.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/23673/1618401709@github.com>

Maarten

unread,
Jul 3, 2023, 5:26:42 PM7/3/23
to wx-...@googlegroups.com, Subscribed

I checked FindOpenGL.cmake and the only path I could find for this behaviour is when OpenGL library is not found, and EGL library is found. Something do to with GLVND.
I'm fine with applying the suggested patch. Maybe with a comment that this is needed for Cygwin.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/23673/1619167288@github.com>

VZ

unread,
Jul 3, 2023, 7:35:00 PM7/3/23
to wx-...@googlegroups.com, Subscribed

Thanks for the confirmation! Will merge soon.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/23673/1619258406@github.com>

Carlo Bramini

unread,
Jul 4, 2023, 3:40:57 AM7/4/23
to wx-...@googlegroups.com, Subscribed

I checked FindOpenGL.cmake and the only path I could find for this behaviour is when OpenGL library is not found, and EGL library is found. Something do to with GLVND. I'm fine with applying the suggested patch. Maybe with a comment that this is needed for Cygwin.

On my system, by searching for installed packages, I have installed this:
immagine

this:
immagine

and this:
immagine

If you would like that I do more tests for getting additional information, I can do them if you give me some instructions,
Thank you very much for your support.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/23673/1619695395@github.com>

VZ

unread,
Jul 7, 2023, 6:58:50 PM7/7/23
to wx-...@googlegroups.com, Subscribed

Closed #23673 as completed via 590cd0b.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issue/23673/issue_event/9759951710@github.com>

Reply all
Reply to author
Forward
0 new messages