Search code examples
c++mingw-w64glew

MinGW GLEW undefined references


When I compile my OpenGL project, I get warnings, then errors:

(Note: The log is too large for Stack Overflow, so I had to submit it to Pastebin, but it also exceeds the 512k limit for Free users, so I had to split it into multiple pastes: https://pastebin.com/4P8HrVs9 https://pastebin.com/NyLn2KWZ https://pastebin.com/VR2LdPDC)

Source for 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;
}

Solution

  • The problem that causes those warnings is that you are including a .c file, specifically #include <glew.c>. You should always only include .h files, unless you know what you are doing and even then it's not advisable.

    There is difference between definitions and declarations in C++. Each variable, function and class can have only one definition in whole project - in all build modules and all linked libraries - but can have multiple declarations. Definitions are in .c files, therefore .c files should never be compiled twice, not even indirectly by including them in different file. You need to #include <GL/glew.h> instead. Short article on this topic is here: https://www.geeksforgeeks.org/difference-between-definition-and-declaration/.

    A strange thing is that you even have file glew.c available to you. That might indicate that you don't have your libraries set up properly, maybe you just downloaded GLEW sources and might have not included it in your project properly. If the undefined reference errors persist even after fixing the wrong include, you need to provide more information about how did you set up you project to link with glew.