基本上,我在Mac上。
我通过自制程序在命令行上安装了glew和glfw3。
现在这些带有.h文件的库位于/ usr / local / include内,我可以无错误地包含它们(智能甚至可以找到方法和东西)。
事实是,与stdio.h string.h iostream ecc不同。包括它们显然还不够。
一旦我构建程序,此消息就会出现在控制台上:
Undefined symbols for architecture x86_64:
"_glewInit", referenced from:
_main in es-97eafd.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我不知道该怎么办,您知道如何正确使用这些库吗?
这些是使glew和glfw3工作所需的步骤。
我假设您已经将它们与brew一起安装:
brew install --universal glew
brew install --universal glfw3
下一步,在编译代码时,需要包含带有-I
标志的标头,并带有如下带有-l
标志的上述库的链接:
-I/usr/local/include -lGLEW -lglfw
一个示例makefile看起来应类似于以下所示,假设我们正在使用这些库在main.c
中开发一个OpenGL应用程序。
BIN = hellot
CC = clang++
FLAGS = -Wall -pedantic -mmacosx-version-min=10.9 -arch x86_64 -fmessage-length=0 -UGLFW_CDECL -fprofile-arcs -ftest-coverage
INC = -I/usr/local/include
LOC_LIB = -lGLEW -lglfw
FRAMEWORKS = -framework Cocoa -framework OpenGL -framework IOKit
SRC = main.c
all:
${CC} ${FLAGS} ${FRAMEWORKS} -o ${BIN} ${SRC} ${INC} ${LOC_LIB}
我包括了sample project on Github as well,它通过渲染3D三角形(图形的问候世界)来演示上述内容。 See the same Makefile listed above here。