更新我切换到介子构建系统。现在一切正常!
我对使用 C++、OpenGl 和 Gnome Builder 非常陌生。我对 C++ 有非常非常基本的基础,并且我知道如何在 CodeLite 中链接头文件和库,但是在弄乱 Gnome Builder 之后,我想进行切换。我还没有找到任何关于使用 Builder 的初学者友好教程。我只是不知道应该如何在 Builder 中链接外部库。我只是手动编辑 Makefile 还是在某个地方设置了可以使用 automake 自动执行 makefile 过程的设置?假设这是一个makefile问题,我错了吗?抱歉,如果这是一个非常新手的问题。
我正在使用 Ubuntu。对于所有 glfw 和 glew 变量和标头,我收到错误“未定义的引用 ...”。使用 apt 安装库后,我将库安装在 usr/lib/x86-64-linux-gnu 中,头文件安装在 usr/include 中。
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
int main ()
{
glewExperimental = true;
if (!glfwInit() )
{
fprintf(stderr, "Failed to initialize GLFW \n");
return -1;
}
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window;
window = glfwCreateWindow(1024, 768, "Tutorial 01", NULL, NULL);
if ( window == NULL )
{
fprintf(stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. \n");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glewExperimental = true;
if (glewInit() != GLEW_OK)
{
fprintf(stderr, "Failed to Initialize GLEW. \n");
return -1;
}
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
do {
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
while ( glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0);
return 0;
}
尝试构建时出现此错误输出〜
g++ -o practice -Wall -ggdb -fno-omit-frame-pointer -O2 practice.cpp /usr/bin/ld: /tmp/ccLx11Ky.o: 在函数
main': /home/joe/Projects/practice/practice.cpp:30: undefined reference to
glewExperimental' /usr/bin/ld: /home/joe /Projects/practice/practice.cpp:31 : 未定义对glfwInit' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:36: undefined reference to
glfwWindowHint' 的引用 /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:37: 未定义对glfwWindowHint' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:38: undefined reference to
glfwWindowHint' 的引用 /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:39:未定义对 glfwWindowHint 的引用glfwWindowHint' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:40: undefined reference to
'/usr/bin/ld:/home/joe/Projects/practice/practice.cpp:43:未定义对glfwCreateWindow' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:50: undefined reference to
glfwMakeContextCurrent'/usr/ 的引用bin/ld: /home/joe/Projects/practice/practice.cpp:51: 未定义引用glewExperimental' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:52: undefined reference to
glewInit' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:58: 未定义引用glfwSetInputMode' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:65: undefined reference to
glfwWindowShouldClose' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:61: 未定义对glClear' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:62: undefined reference to
glfwSwapBuffers' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:63 的引用:未定义对glfwPollEvents' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:65: undefined reference to
glfwGetKey'/usr/bin/ld的引用:/home/joe/Projects/practice/practice.cpp:47:未定义对`glfwTerminate'collect2的引用:错误:ld返回1退出状态make:*** [Makefile :8: 练习] 错误 1
我的默认 Makefile 如下所示~
all: practice
WARNINGS = -Wall
DEBUG = -ggdb -fno-omit-frame-pointer
OPTIMIZE = -O2
practice: Makefile practice.cpp
$(CXX) -o $@ $(WARNINGS) $(DEBUG) $(OPTIMIZE) practice.cpp
clean:
rm -f practice
# Builder will call this to install the application before running.
install:
echo "Installing is not supported"
# Builder uses this target to run your application.
run:
./practice