Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the linker flag for glad on Mac?

This is my makefile

SRC_DIR = src
BUILD_DIR = build/debug
CC = clang++
SRC_FILES = $(wildcard $(SRC_DIR)/*.cpp)
OBJ_NAME = game
INCLUDE_PATHS = -Iinclude
LIBRARY_PATHS = -Llib -Llib//Users/baguma/Downloads/glad-3 -Llib/GL 
COMPILER_FLAGS = -std=c++11 -Wall -O0 -g -arch x86_64 
LINKER_FLAGS = -lglfw3 -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo -lGLEW

all:
    $(CC) $(COMPILER_FLAGS) $(LINKER_FLAGS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(SRC_FILES) -o $(BUILD_DIR)/$(OBJ_NAME)
clean:
    rm -r -f $(BUILD_DIR)/*

This is the error I’m getting:

Undefined symbols for architecture x86_64:
  "_gladLoadGLLoader", referenced from:
      _main in main-d336bf.o
  "_glad_glViewport", referenced from:
      framebuffer_size_callback(GLFWwindow*, int, int) in main-d336bf.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1

Trying to compile a program using OpenGl, glfw and glad

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I can’t seem to find anything helpful by googling.

>Solution :

It looks like the issue you’re encountering is due to the linker not being able to find the GLAD functions. This typically happens when GLAD is not being correctly compiled or linked with your project. Here’s how you can fix this:

  1. Include GLAD in Your Project: Ensure that the glad.c file is included in your source files for compilation. If you’re using a Makefile, you should add glad.c to your SRC_FILES like so:
SRC_FILES = $(wildcard $(SRC_DIR)/*.cpp) path/to/glad.c
  1. Update Include and Library Paths: Verify that your include and library paths in the Makefile are correctly pointing to where GLAD and other dependencies are located. For example:
INCLUDE_PATHS = -Iinclude -Ipath/to/glad
  1. Adjust Linker Flags: Ensure that the linker flags are placed correctly in your compilation command in the Makefile. Flags like -lglfw3 and -lGLEW should come after the source files:
$(CC) $(COMPILER_FLAGS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(SRC_FILES) $(LINKER_FLAGS) -o $(BUILD_DIR)/$(OBJ_NAME)

Here’s an example of how your updated Makefile might look:

SRC_DIR = src
BUILD_DIR = build/debug
CC = clang++
SRC_FILES = $(wildcard $(SRC_DIR)/*.cpp) path/to/glad.c
OBJ_NAME = game
INCLUDE_PATHS = -Iinclude -Ipath/to/glad
LIBRARY_PATHS = -Llib
COMPILER_FLAGS = -std=c++11 -Wall -O0 -g -arch x86_64 
LINKER_FLAGS = -lglfw3 -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo -lGLEW

all:
    $(CC) $(COMPILER_FLAGS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(SRC_FILES) $(LINKER_FLAGS) -o $(BUILD_DIR)/$(OBJ_NAME)
clean:
    rm -r -f $(BUILD_DIR)/*
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading