AiSiBi77 2022-03-30 14:01 采纳率: 0%
浏览 134
已结题

编译报错,opengl 有进来看看么,undefined reference to

问题遇到的现象和发生背景

怎么链接上这些, ubuntu 上安装了这些头文件 , 有知道怎么编译么

问题相关代码
#include <stdio.h>
#include <stdlib.h>

#include <GL/glew.h>
#include <GLFW/glfw3.h>


int main() 
{
    glewExperimental = true;

    if (! glewInit()) {
        fprintf(stderr, "初始化 glew 失败!!");
        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); // To make MacOS happy; should not be needed
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // We don't want the old OpenGL 

    GLFWwindow* window;

    window = glfwCreateWindow(500, 500, "window1", NULL, NULL);

    if (window == NULL) {
        fprintf(stderr, "创建 window 失败!!");
        glfwTerminate();
        return -1;
    }

    glfwMakeContextCurrent(window); // 初始化 glew
    glewExperimental = true;

    if (glewInit() != GLEW_OK) {
        fprintf(stderr, "Failed to initialize GLEW\n");
        return -1;
    }


}
运行结果及报错内容

g++ -o main window.cpp

/usr/bin/ld: /tmp/ccTfugXe.o: in function `main':
window.cpp:(.text+0xe): undefined reference to `glewExperimental'
/usr/bin/ld: window.cpp:(.text+0x14): undefined reference to `glewInit'
/usr/bin/ld: window.cpp:(.text+0x56): undefined reference to `glfwWindowHint'
/usr/bin/ld: window.cpp:(.text+0x65): undefined reference to `glfwWindowHint'
/usr/bin/ld: window.cpp:(.text+0x74): undefined reference to `glfwWindowHint'
/usr/bin/ld: window.cpp:(.text+0x83): undefined reference to `glfwWindowHint'
/usr/bin/ld: window.cpp:(.text+0x92): undefined reference to `glfwWindowHint'
/usr/bin/ld: window.cpp:(.text+0xb3): undefined reference to `glfwCreateWindow'
/usr/bin/ld: window.cpp:(.text+0xe3): undefined reference to `glfwTerminate'
/usr/bin/ld: window.cpp:(.text+0xf6): undefined reference to `glfwMakeContextCurrent'
/usr/bin/ld: window.cpp:(.text+0xfc): undefined reference to `glewExperimental'
/usr/bin/ld: window.cpp:(.text+0x102): undefined reference to `glewInit'
collect2: error: ld returned 1 exit status
  • 写回答

1条回答 默认 最新

  • 丨封尘绝念斩丨 2022-03-30 14:20
    关注

    这不是没装OpenGL吗

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 4月6日
  • 修改了问题 3月30日
  • 创建了问题 3月30日

悬赏问题

  • ¥15 java代码写在记事本上后在cmd上运行时无报错但又没生成文件
  • ¥15 关于#python#的问题:在跑ldsc数据整理的时候一直抱这种错误,要么--out识别不了参数,要么--merge-alleles识别不了参数(操作系统-linux)
  • ¥15 PPOCRLabel
  • ¥15 混合键合键合机对准标识
  • ¥100 现在不懂的是如何将当前的相机中的照片,作为纹理贴图,映射到扫描出的模型上
  • ¥15 魔霸ROG7 pro,win11.息屏后会显示黑屏,如图,如何解决?(关键词-重新启动)
  • ¥15 有没有人知道这是哪里出了问题啊?要怎么改呀?
  • ¥200 C++表格文件处理-悬赏
  • ¥15 Windows Server2016本地登录失败
  • ¥15 复合卡卡号轨道写入芯片卡