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
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:
- Include GLAD in Your Project: Ensure that the
glad.c fileis included in your source files for compilation. If you’re using a Makefile, you should addglad.cto yourSRC_FILESlike so:
SRC_FILES = $(wildcard $(SRC_DIR)/*.cpp) path/to/glad.c
- 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
- Adjust Linker Flags: Ensure that the linker flags are placed correctly in your compilation command in the Makefile. Flags like
-lglfw3and-lGLEWshould 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)/*