Author Topic: Trying to set up glad with glfw3 in Code::Blocks, beginner, please help!  (Read 1493 times)

Offline MokpotheMighty

  • Single posting newcomer
  • *
  • Posts: 2
In short: I'm a c++ beginner looking to set up GLAD with GLFW for a c++ project in Codeblocks, if someone could explain how, or tell me what I did wrong and how to fix it, or learn to fix is, please! It would mean a lot.

Just to be very clear, I'd be perfectly happy if someone could just guide me through the steps of setting up a project with glad in Codeblocks, or show me where I can find it, or how I can learn as a beginner. I'm NOT asking you to fix the code I'm showing, just showing you because the errors it gives me may tell you something about what I'm doing wrong.

I'm trying to learn how to use OpenGL programming with c++ in Codeblocks. The reason is I want to learn by doing something more exciting/creative than writing console apps over and over and learn about all the important stuff that isn't writing code into the IDE: libraries, environments etc... I started watching a Youtube tutorial https://www.youtube.com/watch?v=45MIykWJ-C4 which the first thing it tells you to do is install GLFW and GLAD. I got GLFW to work but not GLAD.

The problem is the tutorial is using VS and I'd really rather use Codeblocks.

I managed to set up GLFW for my project in Codeblocks from watching this https://www.youtube.com/watch?v=CZTEnwYgjag but I couldn't find any source clearly explaining how to do specifically set up GLAD for a project in Codeblocks.

So I tried to approximate what the person in the first video was doing in Codeblocks. I put the files that come with GLAD in the appropriate folders (I'm pretty sure) then I added the glad.c file to my project in the same folder as my main.cpp file. I admit I didn't really know what I was doing so the mistake probably happened there, but I don't even know.

The first code example in the first video (where the main function just returns 0) I got to work.
But then the second example, the one where you're supposed to conjure up a basically functioning window, the errors come... About 24 of them.

Here's the code in my main file:

#include<iostream>
using namespace std;
#include<glad/glad.h>
#include<GLFW/glfw3.h>

int main()
{
    glfwInit();

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    // the first NULL in the next is to say it's NOT fullscreen
    GLFWwindow* window = glfwCreateWindow(800, 800, "YoutubeOpenGL", NULL, NULL);
    if (window == NULL)
    {
        cout << "Failed to create GLFW window" << endl;
        glfwTerminate();
        return -1;
    }

    //we actually need to tell GLFW to use this window too
    // We meet with "context", an object that "holds the whole of OpenGL"
    glfwMakeContextCurrent(window);

    while(!glfwWindowShouldClose(window))
    {
        glfwPollEvents();
    }

    glfwDestroyWindow(window);

    glfwTerminate();
    return 0;
}
This gave me the errors, they all basically have this form:
||=== Build: Debug in Test_GLFW (compiler: GNU GCC MinGW64 Compiler) ===|
C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\x86_64-w64-mingw32\14.2.0\..\..\..\..\x86_64-w64-mingw32\bin\ld.exe: C:\Users\Mokpo\Documents\programming\cpp\GLFW\lib\libglfw3.a(win32_monitor.c.obj):win32_monitor.|| undefined reference to `__imp_CreateDCW'|||=== Build: Debug in Test_GLFW (compiler: GNU GCC MinGW64 Compiler) ===|
C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\x86_64-w64-mingw32\14.2.0\..\..\..\..\x86_64-w64-mingw32\bin\ld.exe: C:\Users\Mokpo\Documents\programming\cpp\GLFW\lib\libglfw3.a(win32_monitor.c.obj):win32_monitor.|| undefined reference to `__imp_CreateDCW'|
Except instead of __imp_CreateDCW, it has different variables at the end like:
__imp_GetDeviceCaps (this one appears multiple times)
__imp_DeleteDC
__imp_CreateDCW


Offline MokpotheMighty

  • Single posting newcomer
  • *
  • Posts: 2
Dual posted:
https://www.reddit.com/r/opengl/comments/1py7xbz/cant_seem_to_get_glad_to_work_in_codeblocks/

Is that something that isn't allowed?
I simply had the idea that I'd ask here since this is after all a specific forum about Code::Blocks and I'm wondering how to set something up specifically in Code::Blocks.