Help with setting up GLFW with glad

My ide is xcode and I want to stress this I am a newbie at these kind of things. I am trying to learn opengl by following this tutorial

removed due to rank

It says to use cmake to build the project solution however attempting to do that seemed to not work with my setup. They used VSC and I used xcode and attempting to replicate what they did didnt work. So I decided to just manually link the headers. I downloaded the source code for glfw and glad and put them in my solution in this order

removed due to rank

Attempting to include the headers like this

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

Only resulted in this very obvious error.

OpenGL header already included, remove this include, glad already provides it

Doing some simple troubleshooting led me to believe that the glfw header should have been included first, however as you can see I already had been doing that. I checked my binary library and I don’t have any sort of opengl framework in there

removed due to rank

I have no idea why this is happening. I am on the latest release of macOS, Big Sur 11.3.1. Any help is appreciated, thanks!

Hi there, try moving glad/glad.h above GLFW/glfw3.h, Cheers

Or add #define GLFW_INCLUDE_NONE just before including glfw. In my code it looks like

#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#include <glad/glad.h>

Because sometimes you need to include glfw earlier than you use glad in another file.

Doing that resulted in the same error. And @FurredDragon that only led to a bad access error to. I should probably note that I believe mac deprecated opengl if that has anything to do with it

I’m not on xcode, but I had the same problem. It isn’t xcode-dependent, it is just a problem of include order.

Do you include glfw in other files? Even in cpp. If so, paste that define right above all of them

Everything I have described in the original post is true. The includes are happening in the main c++ file and glfw is linked confirmed and I am pretty confident I have a directory to glad too. They are in the same include folder after all. However like I said, it says I already have opengl linked, when I dont. Attempting to do what you told me to do led to a bad access 0x0 error.

Fixed it, the problem was that I was doing something very noob. I forgot to generate my cmake build and thus I was using some other library (I assume it was from a different version of glfw)

For any other future internet explorers you may also get some other errors related to the build architecture. 100’s of them. To fix that you need to provide the abstraction from apples metal api to the glfw api by adding these frameworks

Appkit - for docks and icons, etc
Foundation - access to apples window creation sdk
CoreFoundation - this needs to be here for foundation to work
CoreGraphics - pipeline for your gpu and metal, think of this as like the glfw for apple

Make sure also in your header paths to start them as “$(PROJECT_DIR)/” instead of the sdr root you get from dragging the folder in.