Author Topic: Trying to set up glad with glfw3 in Code::Blocks, beginner, please help!  (Read 2913 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.

Online stahta01

  • Lives here!
  • ****
  • Posts: 7811
    • My Best Post
I am willing to help but you need to post the command you used to generate "glad/glad.h" file and post the build log inside code tags.

Edit2: From inside the file "glad/glad.h" you should see a line like
Code
 * Commandline:
 *    --api='gl:core=4.6' --extensions='GL_EXT_framebuffer_multisample,GL_EXT_texture_filter_anisotropic' c

Please post it and/or the steps used to create files using online wizard/web service



Edit: I will be trying to build the code under Windows 11 and MSys2 UCRT 64 bit.

Tim S.
« Last Edit: Today at 11:15:18 am by stahta01 »
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Frank_CB

  • Almost regular
  • **
  • Posts: 158
Use your browser to search for "using opengl in codeblocks". It will return selections for installing codeblocks and videos for using opengl on codeblocks. Also use your browser to search for "opengl tutorials". It's first selection links to an on-line free pdf file that covers opengl pretty thoroughly.

Good luck

Offline Wkerry

  • Multiple posting newcomer
  • *
  • Posts: 113
Tim,

Have a read of the https://www.reddit.com/r/opengl/comments/1py7xbz/cant_seem_to_get_glad_to_work_in_codeblocks/ thread to see what people have already asked and the response as it may save you time and effort.


Online stahta01

  • Lives here!
  • ****
  • Posts: 7811
    • My Best Post
The last two posts in this thread is a waste of bandwidth.

To the OP to build under Code::Blocks you need good [test/example] code to compile and you need to add the source file to the CB project.

Edit: The online script/wizard creates the glad/glad.h file and another source file that needs added to the CB project. Without those two files I cannot do anymore testing. I also need good test code the one I found has run-time issues.

Edit2: The OP needs to find the good test code and post the directions he used with the online wizard/web service for me to do anymore testing. And, if the OP can not post a build log it will be a waste of time for him to continue posting for directions on posting a build log read the CB FAQ on the CB Wiki page.

Edit3: The start of my build log which shows the commands used to build; the OP might get hints from this on the missing libraries that need added.

Code
-------------- Build: Debug in glfw (compiler: GNU GCC Compiler)---------------

gcc.exe -Wall -g -IC:/msys64/ucrt64\include -IGL\include -c C:\devel\test\glfw\GL\src\gl.c -o obj\Debug\GL\src\gl.o
g++.exe -Wall -g -IC:/msys64/ucrt64\include -IGL\include -c C:\devel\test\glfw\main.cpp -o obj\Debug\main.o
g++.exe -LC:/msys64/ucrt64\lib -o bin\Debug\glfw.exe obj\Debug\GL\src\gl.o obj\Debug\main.o   -lglfw3 -lopengl32 -lglu32 -lgdi32
C:\devel\test\glfw\main.cpp: In function 'int main()':
C:\devel\test\glfw\main.cpp:42:10: warning: the address of 'void (* glfwGetProcAddress(const char*))()' will never be NULL [-Waddress]
   42 |     if (!GLADuserptrloadfunc((GLADloadfunc)glfwGetProcAddress)) {
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:\devel\test\glfw\main.cpp:2:
C:/msys64/ucrt64\include/GLFW/glfw3.h:6290:20: note: 'void (* glfwGetProcAddress(const char*))()' declared here
 6290 | GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname);
      |                    ^~~~~~~~~~~~~~~~~~
Output file is bin\Debug\glfw.exe with size 302.21 KB
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 1 warning(s) (0 minute(s), 1 second(s))
 
-------------- Run: Debug in glfw (compiler: GNU GCC Compiler)---------------

Checking for existence: C:\devel\test\glfw\bin\Debug\glfw.exe
Set variable: PATH=.;C:/msys64/ucrt64\lib;C:\msys64\mingw64\bin;C:\msys64\mingw64;C:\msys64\ucrt64\bin;C:\msys64\usr\local\bin;C:\msys64\usr\bin;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\msys64\usr\bin\site_perl;C:\msys64\usr\bin\vendor_perl;C:\msys64\usr\bin\core_perl
Executing: "C:\msys64\ucrt64\bin/cb_console_runner.exe" "C:\devel\test\glfw\bin\Debug\glfw.exe"  (in C:\msys64\ucrt64\bin)
Process terminated with status -1073741819 (0 minute(s), 8 second(s))

Tim S.
« Last Edit: Today at 11:15:55 am by stahta01 »
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org