我正在使用glfw和glew创建窗口,它给了我链接器错误。我如何修复它。这是我第一次安装glfw和glew,所以我可能错过了安装的一个步骤。任何帮助?
我编译我的代码只使用:
gcc main.c
字符串
我知道有一些链接器标志,但glfw和glew不是其中的一部分。
我使用Linux和gcc编译器。
下面是我的代码:
#define GLEW_STATIC
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glfw3.h>
#include <stdbool.h>
int main(){
glewExperimental = true;
if(!glfwInit()){
printf("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, "Game", NULL, NULL);
if(window == NULL){
printf("Sorry to say this, but your OpenGL version must be 3.3 or above! Thanks for playing, but to continue you must update your video card drivers or if you use an old GPU you may have to replace it with a new one to play this game. I will be developing my game for OpenGL 1 and 2 soon so stay on touch.");
glfwTerminate();
return -1;
}
glfwMakeContentCurrent(window);
glewExperimental = true;
if(glewInit() != GLEW_OK){
printf("Failed to initilize GLEW");
return -1;
}
}
型
这是错误日志:
/usr/bin/ld: /tmp/cc74wuFz.o: in function `main':
main.c:(.text+0xe): undefined reference to `glewExperimental'
/usr/bin/ld: main.c:(.text+0x14): undefined reference to `glfwInit'
/usr/bin/ld: main.c:(.text+0x3d): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.c:(.text+0x4c): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.c:(.text+0x5b): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.c:(.text+0x6a): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.c:(.text+0x79): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.c:(.text+0x9a): undefined reference to `glfwCreateWindow'
/usr/bin/ld: main.c:(.text+0xbb): undefined reference to `glfwTerminate'
/usr/bin/ld: main.c:(.text+0xd3): undefined reference to `glfwMakeContentCurrent'
/usr/bin/ld: main.c:(.text+0xd9): undefined reference to `glewExperimental'
/usr/bin/ld: main.c:(.text+0xdf): undefined reference to `glewInit'
collect2: error: ld returned 1 exit status
型
1条答案
按热度按时间a7qyws3x1#
我建议使用类似于
字符串
当然,(在尝试之前)您需要安装OpenGL相关库,可能使用(作为root)以下命令
型
请务必阅读documentation of GCC和documentation of GDB以及documentation of binutils和documentation of pkg-config。
PS.你可以从现有的开源项目的源代码中获得灵感,比如GNU emacs或RefPerSys。