I cannot compile glfw with a Makefile

Asked

Viewed 29 times

0

Hello, a few days ago I felt like learning opengl, and discovered glfw and Glad. I decided to use them to make a little game.

Most tutorials nowadays only talk about how to use them in Visual Studio, but I don’t want to use it because my computer is not very powerful and Visual Studio hangs a lot and is very inefficient when it comes to using, which ends productivity.

So I decided to try to create a Makefile, as I never messed with it I had to challenge myself to create my first.

Here follows the Makefile code:

INCLUDE = -ILibrary/include
LIB = -LLibrary/lib

OBJ = main.o glad.o

CFLAGS = -g -Wall

CFLAGS += $(INCLUDE)
LDFLAGS += $(LIB)

game: $(OBJ)
    g++ -o game.exe $(OBJ) $(CFLAGS) $(LIB) -lglfw3 -lglfw3dll

main.o: src/main.cpp
    g++ -c src/main.cpp $(INCLUDE) $(LIB) -lglfw3 -lglfw3dll

glad.o: Library/include/glad/glad.c Library/include/glad/glad.h
    g++ -c $(INCLUDE)glad/glad.c

For some reason I still don’t know the No Funnel Makefile and accuses the following error:

g++ -c src/main.cpp -ILibrary/include -LLibrary/lib -lglfw3 -lglfw3dll
g++ -o game.exe main.o glad.o -g -Wall -ILibrary/include -LLibrary/lib -lglfw3 -lglfw3dll
main.o:main.cpp:(.text+0xc): undefined reference to `glfwInit'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe: *** [Makefile:12: game] Error 1

Follow my code c++:

#include <iostream>
#include <GLFW/glfw3.h>

int main(void)
{
    if (!glfwInit()) {
        std::cout << "Erro";
    }

    return 0;
}

If anyone can help me, I’d be grateful.

Note: As this is my first Makefile, any criticism of it will be welcome.

  • you are using mingw to run Makefile?

  • glfw is distributed with a complex and complete Makefile. Install Cmake on your machine. Cmakelists.txt is the equivalent file to a Makefile. And on Linux it will even generate a Makefile to compile. On Windows you need to see the generation "target", using cmake -G

  • hello guys, I was out of the O.R.for a while and I ended up solving the problem myself, thanks to everyone who tried to collaborate

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.