c++ - 对 'imp____glewEnableVertexAttribArray' 的 undefined reference

标签 c++ opengl linker undefined-reference

我正在尝试根据用 C++ 编写并打开 gl 2.1 的教程编译我正在做的程序。但是,我不喜欢 FreeGLUT,所以我决定将窗口程序更改为 SFML。然而,我的问题是当我尝试构建程序时出现这些错误:

obj\Debug\main.o||In function `Z6renderv':|
C:\Users\Jordanh\Documents\Code Blocks\GL_2-Lesson-1\main.cpp|36|undefined reference to `_imp____glewUseProgram'|
C:\Users\Jordanh\Documents\Code Blocks\GL_2-Lesson-1\main.cpp|37|undefined reference to `_imp____glewEnableVertexAttribArray'|
C:\Users\Jordanh\Documents\Code Blocks\GL_2-Lesson-1\main.cpp|52|undefined reference to `_imp____glewVertexAttribPointer'|
C:\Users\Jordanh\Documents\Code Blocks\GL_2-Lesson-1\main.cpp|56|undefined reference to `_imp____glewDisableVertexAttribArray'|
obj\Debug\main.o||In function `Z11initShadersv':|
C:\Users\Jordanh\Documents\Code Blocks\GL_2-Lesson-1\main.cpp|62|undefined reference to `_imp____glewCreateProgram'|
C:\Users\Jordanh\Documents\Code Blocks\GL_2-Lesson-1\main.cpp|67|undefined reference to `_imp____glewLinkProgram'|
C:\Users\Jordanh\Documents\Code Blocks\GL_2-Lesson-1\main.cpp|68|undefined reference to `_imp____glewGetProgramiv'|
C:\Users\Jordanh\Documents\Code Blocks\GL_2-Lesson-1\main.cpp|76|undefined reference to `_imp____glewGetAttribLocation'|
obj\Debug\main.o||In function `Z16initVertexShaderv':|
C:\Users\Jordanh\Documents\Code Blocks\GL_2-Lesson-1\main.cpp|86|undefined reference to `_imp____glewCreateShader'|
C:\Users\Jordanh\Documents\Code Blocks\GL_2-Lesson-1\main.cpp|95|undefined reference to `_imp____glewShaderSource'|
C:\Users\Jordanh\Documents\Code Blocks\GL_2-Lesson-1\main.cpp|96|undefined reference to `_imp____glewCompileShader'|
C:\Users\Jordanh\Documents\Code Blocks\GL_2-Lesson-1\main.cpp|97|undefined reference to `_imp____glewGetShaderiv'|
C:\Users\Jordanh\Documents\Code Blocks\GL_2-Lesson-1\main.cpp|103|undefined reference to `_imp____glewAttachShader'|
obj\Debug\main.o||In function `Z18initFragmentShaderv':|
C:\Users\Jordanh\Documents\Code Blocks\GL_2-Lesson-1\main.cpp|109|undefined reference to `_imp____glewCreateShader'|
C:\Users\Jordanh\Documents\Code Blocks\GL_2-Lesson-1\main.cpp|119|undefined reference to `_imp____glewShaderSource'|
C:\Users\Jordanh\Documents\Code Blocks\GL_2-Lesson-1\main.cpp|120|undefined reference to `_imp____glewCompileShader'|
C:\Users\Jordanh\Documents\Code Blocks\GL_2-Lesson-1\main.cpp|121|undefined reference to `_imp____glewGetShaderiv'|
C:\Users\Jordanh\Documents\Code Blocks\GL_2-Lesson-1\main.cpp|128|undefined reference to `_imp____glewAttachShader'|
||=== Build finished: 18 errors, 0 warnings ===|

我在程序中包含了以下库:

#include <GL/glew.h>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

我还链接了这些:

-lsfml-system
-lsfml-window
-lopengl32
-lglu32
-lglew32

最佳答案

*_imp__* 类型的 undefined reference (名称修改)是由于尝试链接由/为 Visual Studio/MSVC 编译的库而引起的。

解决方案是下载二进制文件或针对您的特定平台进行编译(这通常与 mingw32 相关)。

关于c++ - 对 'imp____glewEnableVertexAttribArray' 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11423700/

相关文章:

opengl - 一种生成 block 的方法

javascript - 如何在 WebGl 中使用漫射照明进行 Gouraud 着色?

C++ 仍在寻找 .lib 文件,但我不明白为什么

c++ - 链接错误、未解析的符号 QString、QComboBox、QSlider、QAbstractButton、QRadioButton、

macos - 防止函数插入链接到执行插入的库的库中

c++ - 带有 CKKS 的 Microsoft SEAL 中的 vector 点积

python - 使用 Cython 时如何将一个 C++ 类(引用)传递给另一个类?

c++ - 解析分配给默认参数值的重载函数时考虑了哪些函数集?

c++ - 静态和重新解释类型转换 - 定义的行为?

ruby - 带有 Ruby 的 OpenGL 3.1+