在命令行 mac 上链接 GLEW 和 GLFW3

Linking GLEW and GLFW3 on mac on command line

基本上,我在 mac。

我通过自制软件在命令行上安装了 glew 和 glfw3。

现在这些带有 .h 文件的库都在 /usr/local/include 中,我可以毫无错误地包含它们(intellisense 甚至可以找到方法和东西)。

问题是,不像 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 标志的 headers 和带有 -l 标志的 link 包含到上述库中,如下所示:

-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 which demonstrates the above by rendering a 3D triangle, the hello world of graphics. See the same Makefile listed above here