Why can’t i properly link opengl libraries? (Windows, mingw, command line)

So basically what i am trying to do, is setting up opengl on a windows pc without VS. This is a pain, since every damn tutorial on this planet uses Visual Studio, but i simply hate it so i will not use it. What i did was downloading all the necessary libraries, setting up a project, creating a main file and than a Makefile. main.cpp:

#include <windows.h>
#include <GL/glut.h>

int main(int argc, char** argv){
    return 0;

My Makefile:

INCL_DIR = include
SRC_DIR = src
LIB_DIR = lib
BUILD_DIR = build
OUTPUT_NAME = graph.exe

CXX = g++
LDFLAGS = -L$(LIB_DIR) -lfreeglut -lglew32 -lopengl32 -lgdi32 -lwinmm

SRCS := $(wildcard $(SRC_DIR)/*.cpp)
OBJS := $(SRCS:%.cpp=%.o)


    del /f $(SRC_DIR)\*.o
    del /f $(BUILD_DIR)\$(OUTPUT_NAME)

The project hierarchy: Picture of the project hierarchy in VSCode

What happens when i run make:

PS C:\programming\projects\opengl_base> make
g++ -Iinclude    -c -o src/main.o src/main.cpp
g++ -o build/graph.exe src/main.o -Iinclude 
src/main.o:main.cpp:(.text+0x23): undefined reference to `__glutInitWithExit'
src/main.o:main.cpp:(.text+0x46): undefined reference to `__glutCreateWindowWithExit'
src/main.o:main.cpp:(.text+0x68): undefined reference to `__glutCreateMenuWithExit'
src/main.o:main.cpp:(.text+0xad): undefined reference to `glutInitWindowSize'
src/main.o:main.cpp:(.text+0xb2): undefined reference to `glutMainLoop'
collect2.exe: error: ld returned 1 exit status
make: *** [graph.exe] Error 1

What i understand is, that the libraries simply don't get linked for some reason. But why? Please help me

Read more here: https://stackoverflow.com/questions/66329064/why-cant-i-properly-link-opengl-libraries-windows-mingw-command-line

Content Attribution

This content was originally published by RipplB at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: