MinGW GLEW 未定义引用

MinGW GLEW undefined references

当我编译我的 OpenGL 项目时,我收到警告,然后是错误:

(注:由于Stack Overflow日志太大,只好提交到Pastebin,但也超过了Free用户512k的限制,只好拆分成多个粘贴:https://pastebin.com/4P8HrVs9 https://pastebin.com/NyLn2KWZ https://pastebin.com/VR2LdPDC)

main.cpp 的来源:

/* Test Game Main Source File
 * Copyright (C) 2020 (REDACTED)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version. */

#include <iostream>
#include <glew.c>
using namespace std;

int main() {
    return 0;
}

导致这些警告的问题是您包含了一个 .c 文件,特别是 #include <glew.c>。您应该始终只包含 .h 文件,除非您知道自己在做什么,即使这样也是不可取的。

C++ 中的 定义 声明 之间存在差异。每个变量、函数和 class 在整个项目中只能有一个定义 - 在所有构建模块和所有 linked 库中 - 但可以有多个声明。定义在 .c 文件中,因此 .c 文件不应该被编译两次,甚至不应该通过将它们包含在不同的文件中来间接编译。您需要 #include <GL/glew.h> 来代替。关于这个主题的短文在这里:https://www.geeksforgeeks.org/difference-between-definition-and-declaration/.

奇怪的是,您甚至可以使用文件 glew.c。这可能表明您没有正确设置您的库,也许您只是下载了 GLEW 源并且可能没有将它正确地包含在您的项目中。如果即使在修复错误的包含后未定义的引用错误仍然存​​在,您需要提供更多信息,说明您是如何使用 glew.link 设置项目的。