[英]Errors during linking GLFW files
I have built GLFW from source and trying to build applications with it on Ubuntu Linux.我已经从源代码构建了 GLFW,并尝试在 Ubuntu Linux 上构建应用程序。 But, g++
is always throwing errors about undefined references.但是, g++
总是抛出关于未定义引用的错误。 I have followed many sites and posts, but they didn't solve my problem.我关注了许多网站和帖子,但它们并没有解决我的问题。 This is my code:这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
using namespace glm;
int main() {
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. Try the 2.1 version of the tutorials.\n" );
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glewExperimental=true;
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
return -1;
}
return 0;
}
I am compiling this program with this command: g++ glfw_prog.cpp -lGL -lglfw3 -o glfw_prog
.我正在使用以下命令编译此程序: g++ glfw_prog.cpp -lGL -lglfw3 -o glfw_prog
。
But, I am getting this long error https://pastebin.com/1b8fB2h7 .但是,我收到了这个长错误https://pastebin.com/1b8fB2h7 。
How to fix this problem?如何解决这个问题?
I got your program to compile with the following flags on Ubuntu:我让您的程序在 Ubuntu 上使用以下标志进行编译:
g++ glfw_prog.cpp -lGL -lglfw -lGLEW -o glfw_prog
I have followed this site and solved my problem.我已经关注了这个网站并解决了我的问题。 I had to use the command gcc -o glfw_prog glfw_prog.cpp $(pkg-config --static --libs glfw3) -lGLEW
.我不得不使用命令gcc -o glfw_prog glfw_prog.cpp $(pkg-config --static --libs glfw3) -lGLEW
。 I just had to add the extra -lGLEW
flag along with the pkg-config search path.我只需要添加额外的-lGLEW
标志以及 pkg-config 搜索路径。
More specifically, this is the complete and system-independent command:更具体地说,这是完整且独立于系统的命令:
gcc -o glfw_prog glfw_prog.cpp -L/usr/local/lib -lglfw3 -lrt -lm -ldl -lX11 -lpthread -lxcb -lXau -lXdmcp -lGLEW -lGL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.