gpt4 book ai didi

linux - 在 Linux 上使用 glad 的 OpenGL Makefile

转载 作者:太空宇宙 更新时间:2023-11-04 12:13:29 24 4
gpt4 key购买 nike

我想在我的 OpenGL 项目中使用 glad,但我不太确定如何为它创建 Makefile。我从网络服务中下载了 glad 并将目录从 include/(glad/和 KHR/)移动到/usr/include/(现在 emacs 看到了库)和 glad.c 文件到我项目的根目录(目前仅包含一个演示 source.cpp 文件)。

我有这个 Makefile:

UNAME_S := $(shell uname -s)

ifeq ($(UNAME_S), Linux)
COMPILER = g++
FLAGS = -std=c++1y -pedantic -Wall
GL_FLAGS = -lGL -lglfw
endif
ifeq ($(UNAME_S), Darwin)
COMPILER = clang++
FLAGS = -std=c++1y -stdlib=libc++ -pedantic -Wall
GL_FLAGS = -lGLEW -framework OpenGL -lm
endif
FILES = $(wildcard *.cpp)
APP_NAME = opengl-app

all: main

main: $(FILES)
$(COMPILER) $(FLAGS) $(FILES) glad.c -o $(APP_NAME) $(GL_FLAGS)

.PHONY: clean run
clean:
rm opengl-app

run: opengl-app
./opengl-app

执行时出现以下错误:

/usr/bin/ld: /tmp/cc0DUjDZ.o: undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
/usr/lib/libdl.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

我们将不胜感激任何有关 makefile 的帮助。

最佳答案

正如@G.M. 在评论中提到的。 glad 使用 dlopen/dlclose,这些方法用于在 Linux 中加载共享对象。

Makefile 应该添加链接标志以使用libdl.so。最后的结果应该是这样的:

UNAME_S := $(shell uname -s)

ifeq ($(UNAME_S), Linux)
COMPILER = g++
FLAGS = -std=c++1y -pedantic -Wall
GL_FLAGS = -lGL -lglfw
endif
ifeq ($(UNAME_S), Darwin)
COMPILER = clang++
FLAGS = -std=c++1y -stdlib=libc++ -pedantic -Wall
GL_FLAGS = -lGLEW -framework OpenGL -lm
GLAD_FLAGS = -ldl
endif
FILES = $(wildcard *.cpp)
APP_NAME = opengl-app

all: main

main: $(FILES)
$(COMPILER) $(FLAGS) $(FILES) glad.c -o $(APP_NAME) $(GL_FLAGS) $(GLAD_FLAGS)

.PHONY: clean run
clean:
rm opengl-app

run: opengl-app
./opengl-app

关于linux - 在 Linux 上使用 glad 的 OpenGL Makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48136263/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com