How do I include a c/c++ library in vscode with Makefile

386 Views Asked by At

I usually use Visual Studio for c/c++ programming, however I want to give vscode a shot and I don't know how to include libraries using Makefile. (The tutorials on youtube didn't work) I tried using C/C++ Configurations (IntelliSense Configurations) but doesn't work.

I want to include GLFW and GLAD.

Project Library Paths: C:\Users\Administrator\Documents\Game Project\include\GLAD and C:\Users\Administrator\Documents\Game Project\include\GLFW

The Makefile:

all:
    g++ -g --std=c++20 -I../include -L../lib ../src/*.cpp ../src/glad.c -lglfw3dll -o main

(Got this from the youtube tutorial)

It always gives me the "No such file or directory" error.

Please help

1

There are 1 best solutions below

0
On

If your include directory is C:\Users\Administrator\Documents\Game Project\include\GLFW in that it is this directory that contains your header files, then the -I should end in GLFW because that is the directory your headers are in. The same applies to the -L switch.

Your command line should look something like

g++ -g --std=c++20 -I../include/GLFW -I../include/GLAD -L../lib/GLFW  -L../lib/GLAD ../src/*.cpp ../src/glad.c -lglfw3dll -o main

You can have multiple -I switches for multiple directories (as you have here) and the same for -L.

I was guessing above that the libraries are in subdirectories like the headers, btw. But the rule is the same as for headers: The -L path(s) must point to the directory containing the libraries, not any parent of that directory.