这是我的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)/*
这是我遇到的错误:
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
尝试使用 OpenGl、glfw 和 happy 编译程序
我似乎无法通过谷歌搜索找到任何有用的东西。
您遇到的问题似乎是由于链接器无法找到 GLAD 函数造成的。当 GLAD 未正确编译或与您的项目链接时,通常会发生这种情况。以下是解决此问题的方法:
glad.c file
包含在您的源文件中进行编译。如果您使用的是 Makefile,您应该将 glad.c
添加到您的 SRC_FILES
,如下所示:SRC_FILES = $(wildcard $(SRC_DIR)/*.cpp) path/to/glad.c
INCLUDE_PATHS = -Iinclude -Ipath/to/glad
-lglfw3
和 -lGLEW
这样的标志应该出现在源文件之后:$(CC) $(COMPILER_FLAGS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(SRC_FILES) $(LINKER_FLAGS) -o $(BUILD_DIR)/$(OBJ_NAME)
以下是更新后的 Makefile 的示例:
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)/*