我正在使用 glfw 和 glew 創建視窗,它給了我聯結器錯誤。我該如何解決。這是我第一次安裝 glfw 和 glew,所以我可能會錯過安裝中的一個步驟。有什么幫助嗎?
我只使用以下命令編譯我的代碼:
gcc main.c
我知道有一些聯結器標志,但 glfw 和 glew 不是其中的一部分。
我使用帶有 gcc 編譯器的 linux。
這是我的代碼:
#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
uj5u.com熱心網友回復:
我建議使用類似于的命令進行編譯
gcc -Wall -Wextra -g $(pkg-config --cflags opengl glfw3) main.c \
$(pkg-config --libs opengl glfw3) -o prog
當然(在嘗試之前)您需要安裝 OpenGL 相關庫,可能使用(作為 root)以下命令
aptitude install libopengl-dev libglfw3-dev
請務必閱讀GCC的檔案和 GDB的檔案以及 binutils的檔案和 pkg-config的檔案。
附注。您可以從現有開源專案的源代碼中獲得靈感,例如GNU emacs或RefPerSys。
注意。您可以通過電子郵件與我聯系:([email protected]家)或[email protected](辦公室,在CEA,LIST ....)在法國巴黎附近。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/356327.html
上一篇:除錯C程式時VisualStudioCode中的分段錯誤
下一篇:如何顯示和添加所有偶數?
