MinGW GLEW未定义参考

问题描述

当我编译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 ++中,定义声明之间是有区别的。每个变量,函数和类在整个项目中(在所有构建模块和所有链接的库中)只能有一个定义,但可以有多个声明。定义位于.c文件中,因此.c文件绝对不应编译两次,甚至不能通过将它们包含在其他文件中来间接编译。您需要改为#include <GL/glew.h>。有关此主题的简短文章在这里:https://www.geeksforgeeks.org/difference-between-definition-and-declaration/

奇怪的是,您甚至还可以使用文件 glew.c 。这可能表明您没有正确设置库,也许您只是下载了GLEW源,并且可能未将其正确包含在项目中。如果即使解决了错误的include后仍存在未定义的参考错误,则需要提供有关如何设置项目以与glew链接的更多信息。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...