c++notepad++mingwglfwglad

How to include Libraries without an IDE


I just downloaded the MingW Compiler and the glfw and glad libraries. i set up Notepad++ to compile with mingW and now i cant figure out how to include the above mentiond libraries. do i have to put the .h files in my folder with my main.cpp file or smth? where do i have to unzip my libraries to. I have absolutly no idea and have been searching the web for hours.

I have unzipped the libs into the same folder as the main.cpp file and then called smth like this in the main.cpp include<librariename/include/lib.h>


Solution

  • First of all, consider MinGW-w64, it's much more up to date than MinGW and supports both Windows 32-bit and 64-bit. You can get standalone versions from https://winlibs.com/, or you can install it from MSYS2 using pacman.

    To use a library you need to do several things:

    So for example if you have the following files:

    Then you shoule add #include <GL/glfw.h to your code and build like this (if your code is in main.c):

    gcc -c -o main.o main.c -I/C/Temp/include
    gcc -o main.exe main.o -L/C/Temp/lib -lglfw
    

    In the above example the first line is the compiler step and the second line the linker step. You could combine both steps like this:

    gcc -o main.exe main.c -I/C/Temp/include -L/C/Temp/lib -lglfw
    

    But as your project grows it's better to keep compiler and linker steps separated.

    In fact, as your project grows you may want to consider using some kine of build system (like make or cmake).