Skip to content

[qt examples] lld-link: error: undefined symbol of opengl functions #40

Closed

Description

@miyanyan

platform:
win11 + clang-cl + qt5.15.2
or
win11 + msvc + qt5.15.2

all qt examples got such errors:

[build] LINK: command "C:\PROGRA~1\MICROS~3\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\lld-link.exe /nologo examples\qt\graph1\CMakeFiles\qtgraph1.dir\qtgraph1_autogen\mocs_compilation.cpp.obj examples\qt\graph1\CMakeFiles\qtgraph1.dir\main.cpp.obj /out:examples\qt\graph1\qtgraph1.exe /implib:examples\qt\graph1\qtgraph1.lib /pdb:examples\qt\graph1\qtgraph1.pdb /version:0.0 /machine:x64 /INCREMENTAL:NO /subsystem:console C:\Qt\5.15.2\msvc2019_64\lib\Qt5OpenGL.lib C:\Qt\5.15.2\msvc2019_64\lib\Qt5Widgets.lib C:\Qt\5.15.2\msvc2019_64\lib\Qt5Gui.lib C:\Qt\5.15.2\msvc2019_64\lib\Qt5Core.lib D:\github\vcpkg\installed\x64-windows\lib\freetype.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST:EMBED,ID=1" failed (exit code 1) with the following output:
[build] lld-link: error: undefined symbol: __declspec(dllimport) glGetError
[build] >>> referenced by examples\qt\graph1\CMakeFiles\qtgraph1.dir\main.cpp.obj:(unsigned int __cdecl mplot::gl::Util::checkError(char const *, int))
[build] >>> referenced by examples\qt\graph1\CMakeFiles\qtgraph1.dir\main.cpp.obj:(unsigned int __cdecl mplot::gl::Util::checkError(char const *, int))
[build] >>> referenced by examples\qt\graph1\CMakeFiles\qtgraph1.dir\main.cpp.obj:(unsigned int __cdecl mplot::gl::LoadShaders(class std::vector<struct mplot::gl::ShaderInfo, class std::allocator<struct mplot::gl::ShaderInfo>> const &))
[build] 
[build] lld-link: error: undefined symbol: glCreateProgram
[build] >>> referenced by examples\qt\graph1\CMakeFiles\qtgraph1.dir\main.cpp.obj:(unsigned int __cdecl mplot::gl::LoadShaders(class std::vector<struct mplot::gl::ShaderInfo, class std::allocator<struct mplot::gl::ShaderInfo>> const &))
[build] 
[build] lld-link: error: undefined symbol: __declspec(dllimport) glGetBooleanv
[build] >>> referenced by examples\qt\graph1\CMakeFiles\qtgraph1.dir\main.cpp.obj:(unsigned int __cdecl mplot::gl::LoadShaders(class std::vector<struct mplot::gl::ShaderInfo, class std::allocator<struct mplot::gl::ShaderInfo>> const &))
[build] 
[build] lld-link: error: undefined symbol: glCreateShader
[build] >>> referenced by examples\qt\graph1\CMakeFiles\qtgraph1.dir\main.cpp.obj:(unsigned int __cdecl mplot::gl::LoadShaders(class std::vector<struct mplot::gl::ShaderInfo, class std::allocator<struct mplot::gl::ShaderInfo>> const &))
[build] 
[build] lld-link: error: undefined symbol: glShaderSource
[build] >>> referenced by examples\qt\graph1\CMakeFiles\qtgraph1.dir\main.cpp.obj:(unsigned int __cdecl mplot::gl::LoadShaders(class std::vector<struct mplot::gl::ShaderInfo, class std::allocator<struct mplot::gl::ShaderInfo>> const &))

I tried to link Qt5::OpenGL instead, it also doesn't work

Activity

  1. linked a pull request that will close this issueAdds some missing #includes #41on Jul 22, 2025
  2. sebsjames commented on Jul 22, 2025

    @sebsjames
    Owner

    I added some missing include lines, see if that fixes the compiler error for you.

  3. sebsjames commented on Jul 22, 2025

    @sebsjames
    Owner

    I've merged the change, as it was correct to add the includes in. I've left this issue open, so please close it if your problem has vanished on current main.

  4. miyanyan commented on Jul 23, 2025

    @miyanyan
    ContributorAuthor

    I've merged the change, as it was correct to add the includes in. I've left this issue open, so please close it if your problem has vanished on current main.

    still got these errors, I think it's maybe something that doesn't link opengl properly?

    [build] LINK: command "C:\PROGRA~1\MICROS~3\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\lld-link.exe /nologo examples\qt\graph1\CMakeFiles\qtgraph1.dir\qtgraph1_autogen\mocs_compilation.cpp.obj examples\qt\graph1\CMakeFiles\qtgraph1.dir\main.cpp.obj /out:examples\qt\graph1\qtgraph1.exe /implib:examples\qt\graph1\qtgraph1.lib /pdb:examples\qt\graph1\qtgraph1.pdb /version:0.0 /machine:x64 /INCREMENTAL:NO /subsystem:console C:\Qt\5.15.2\msvc2019_64\lib\Qt5Widgets.lib opengl32.lib D:\github\vcpkg\installed\x64-windows\lib\glfw3dll.lib C:\Qt\5.15.2\msvc2019_64\lib\Qt5Gui.lib C:\Qt\5.15.2\msvc2019_64\lib\Qt5Core.lib D:\github\vcpkg\installed\x64-windows\lib\freetype.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST:EMBED,ID=1" failed (exit code 1) with the following output:
    
  5. sebsjames commented on Jul 23, 2025

    @sebsjames
    Owner

    Ah, so you're right. I didn't read the original error messages carefully enough. Seems like this is probably Qt shared object libraries being linked to OpenGL on Linux/Mac but not on Windows.

  6. sebsjames commented on Jul 23, 2025

    @sebsjames
    Owner

    It may also be a question of GL header inclusion.

  7. sebsjames commented on Jul 23, 2025

    @sebsjames
    Owner

    I think the problem might be GL header inclusion (as the build process appears to be linking to opengl already).

    When we use OpenGL, we have to define function names that map to the internal function names. One way to do this is to use GLAD (which I do in mathplot). Qt does this itself with the QOpenGLFunctions_* classes.

    There is a note at the top of mplot/qt/viswidget.h:

    #include <QOpenGLFunctions_4_1_Core> // problem is that this loads GL headers, so we don't load glad, further on

    So, on platforms that I've tested Qt with (i.e. Linux), when you #include <QOpenGLFunctions_4_1_Core>, the function mapping is made so that when we #include <mplot/VisualOwnableNoMX.h> and start preprocessing that file we process this:

    #if defined __gl3_h_ || defined __gl_h_ // could get a fuller list from glfw.h
    // GL headers appear to have been externally included.
    #else
    // Include GLAD header
    # define GLAD_GL_IMPLEMENTATION
    #  include <mplot/glad/gl.h>
    #endif // GL headers

    You could add some pragma message lines to that section (or something that will emit a message for your compiler) like this:

    #if defined __gl3_h_ || defined __gl_h_ // could get a fuller list from glfw.h
    // GL headers appear to have been externally included.
    #pragma message "GL headers appear to have been externally included"
    #else
    #pragma message "GL headers appear NOT to have been externally included, will include mplot/glad/gl.h"
    // Include GLAD header
    # define GLAD_GL_IMPLEMENTATION
    #  include <mplot/glad/gl.h>
    #endif // GL headers

    On Linux with gcc I get this output when building qtgraph1 with the above change to mplot/VisualOwnableNoMX.h:

    [seb@GPU3090 10:36:13 build]$ make qtgraph1
    [  0%] Built target qtgraph1_autogen_timestamp_deps
    [ 50%] Built target qtgraph1_autogen
    [ 50%] Building CXX object examples/qt/graph1/CMakeFiles/qtgraph1.dir/main.cpp.o
    In file included from /home/seb/src/mathplot/mplot/qt/viswidget.h:15,
                     from /home/seb/src/mathplot/examples/qt/graph1/main.cpp:3:
    /home/seb/src/mathplot/mplot/VisualOwnableNoMX.h:21:17: note: ‘#pragma message: GL headers appear to have been externally included’
       21 | #pragma message "GL headers appear to have been externally included"
          |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    [ 50%] Linking CXX executable qtgraph1
    [100%] Built target qtgraph1
    [seb@GPU3090 10:37:03 build]$

    Could you try this and see what output you get?

  8. miyanyan commented on Jul 23, 2025

    @miyanyan
    ContributorAuthor

    I got the same output:

    [build] In file included from D:\github\miyanyan\mathplot\examples\qt\fps\mainwindow.cpp:8:
    [build] In file included from D:\github\miyanyan\mathplot\mplot/qt/viswidget.h:15:
    [build] D:\github\miyanyan\mathplot\mplot/VisualOwnableNoMX.h(21,9): warning: GL headers appear to have been externally included [-W#pragma-messages]
    [build]    21 | #pragma message "GL headers appear to have been externally included"
    [build]       |         ^
    [build] 1 warning generated.
    [build] [274/276  99% :: 112.557] Building CXX object examples\qt\hexgrid\CMakeFiles\qthexgrid.dir\mainwindow.cpp.obj
    [build] In file included from D:\github\miyanyan\mathplot\examples\qt\hexgrid\mainwindow.cpp:8:
    [build] In file included from D:\github\miyanyan\mathplot\mplot/qt/viswidget.h:15:
    [build] D:\github\miyanyan\mathplot\mplot/VisualOwnableNoMX.h(21,9): warning: GL headers appear to have been externally included [-W#pragma-messages]
    [build]    21 | #pragma message "GL headers appear to have been externally included"
    [build]       |         ^
    [build] 1 warning generated.
    
  9. sebsjames commented on Jul 24, 2025

    @sebsjames
    Owner

    Maybe the best way to approach this is for me to get the same error you have on a Windows machine. Can you tell me how you installed dependencies and carried out the build? You could even write notes into a PR for https://github.com/sebsjames/mathplot/blob/main/README.build.windows.md

    I can then try to build and see if I get the same link error and can try to fix locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions