【发布时间】:2014-05-06 21:54:39
【问题描述】:
我意识到以前有人问过类似的问题 (glfw3 compiling undefined references),但不幸的是我仍然无法让它工作。欢迎任何帮助!
下面是运行make时的编译器输出:
g++ -std=c++11 -Wall -Wextra -Werror -pedantic-errors -I/usr/local/include -c -o Main.o Main.cpp
g++ -std=c++11 -Wall -Wextra -Werror -pedantic-errors -I/usr/local/include -L/usr/local/lib -lglfw3 -lGL Main.o -o modernogl
Main.o:在函数“main”中:
Main.cpp:(.text+0x9): undefined reference to `glfwInit'
Main.cpp:(.text+0x3b): 对 `glfwCreateWindow' 的未定义引用
Main.cpp:(.text+0x4b): undefined reference to `glfwTerminate'
Main.cpp:(.text+0x5e): 对`glfwMakeContextCurrent'的未定义引用
Main.cpp:(.text+0x6c): 对 `glfwSwapBuffers' 的未定义引用
Main.cpp:(.text+0x71): 未定义对 `glfwPollEvents' 的引用
Main.cpp:(.text+0x7d): 对 `glfwWindowShouldClose' 的未定义引用
Main.cpp:(.text+0x92): undefined reference to `glfwDestroyWindow'
Main.cpp:(.text+0x97): 对 `glfwTerminate' 的未定义引用
collect2: 错误:ld 返回 1 个退出状态
make: *** [modernogl] 错误 1
这是 include 和 lib 目录在其中的内容:http://imgur.com/e6qXSjB,fASlBUm#1
以下是出处(不过应该没有问题……):
#include <GLFW/glfw3.h>
int main() {
if (!glfwInit()) {
return 1;
}
GLFWwindow* window {glfwCreateWindow(640, 480, "Modern OpenGL", nullptr, nullptr)};
if (!window) {
glfwTerminate();
return 1;
}
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window)) {
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
非常感谢您的帮助! - 埃里克
【问题讨论】:
标签: c++ c++11 g++ undefined-reference glfw