0

I'm attempting to start an OpenGL/C++ project using GLFW3 and GLAD and with vcpkg as package manager. I use vcpkg in manifest mode. The project compiles fine, as long as I only use GLFW3, so I have all the basics up and running. vcpkg installs, the toolchain loads fine, etc.

However, when I start using GLAD I see these errors. For the record, I can include glad/glad.h in the project fine - the compiler doesn't complain until I attempt to use it.

vcpkg_installed/x64-windows/debug/lib/glad.lib(CMakeFiles/glad.dir/src/glad.c.obj):(.text$mn+0x28a): undefined reference to `fprintf'
vcpkg_installed/x64-windows/debug/lib/glad.lib(CMakeFiles/glad.dir/src/glad.c.obj):(.text$mn+0x2ecad): undefined reference to `__security_cookie'
vcpkg_installed/x64-windows/debug/lib/glad.lib(CMakeFiles/glad.dir/src/glad.c.obj):(.text$mn+0x2ed9b): undefined reference to `sscanf_s'
vcpkg_installed/x64-windows/debug/lib/glad.lib(CMakeFiles/glad.dir/src/glad.c.obj):(.text$mn+0x2f24f): undefined reference to `_RTC_CheckStackVars'
vcpkg_installed/x64-windows/debug/lib/glad.lib(CMakeFiles/glad.dir/src/glad.c.obj):(.text$mn+0x2f25f): undefined reference to `__security_check_cookie'
vcpkg_installed/x64-windows/debug/lib/glad.lib(CMakeFiles/glad.dir/src/glad.c.obj):(.xdata+0x21d8): undefined reference to `__GSHandlerCheck'
vcpkg_installed/x64-windows/debug/lib/glad.lib(CMakeFiles/glad.dir/src/glad.c.obj):(.rtc$IMZ+0x0): undefined reference to `_RTC_InitBase'
vcpkg_installed/x64-windows/debug/lib/glad.lib(CMakeFiles/glad.dir/src/glad.c.obj):(.rtc$TMZ+0x0): undefined reference to `_RTC_Shutdown'

I have also tried installing a few other libraries, such as GLM, that also works fine. So it seems to be something specific to the GLAD library.

I'm using MingW compiler (in CLion).

An interesting note is that the x64-windows directory doesn't have the debug folder, only the x86-windows folder does. So maybe the issue lies there?

I have googled and ChatGPT'ed the problem to death.

CMakeLists.txt

cmake_minimum_required(VERSION 3.25)
project(vcpkg)

set(CMAKE_CXX_STANDARD 14)

find_package(glfw3 CONFIG REQUIRED)
find_package(glad CONFIG REQUIRED)
find_package(OpenGL REQUIRED)

add_executable(vcpkg main.cpp)

target_link_libraries(vcpkg PRIVATE glad::glad opengl32 glfw)

main.cpp:

#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>

int main() {
    glfwInit();
    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
    {
        std::cout << "Failed to initialize GLAD" << std::endl;
        return -1;
    }
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

And for the record vcpkg.json:

{
  "dependencies": [
    "glad",
    "glfw3"
  ]
}

Which was installed with vcpkg install (which creates the vcpkg_installed folder at the root of the project).

I also tried provoking GLAD to not load, and then the undefined functions were different. So it does load GLAD to some extend. It seems it's using some "deeper" functions, which it can't load.

Am I maybe missing more libraries in the CMake? But isn't vcpkg supposed to handle dependencies for us?

I hope someone has pointers to move on from here :-)

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Jens
  • 1,302
  • 1
  • 13
  • 20

0 Answers0