-1

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

drescherjm
  • 10,365
  • 5
  • 44
  • 64
  • 1
    Can you show what you have got so far in your `Makefile` please. – JeremyP Jan 09 '23 at 15:04
  • My guess is your problem is caused by the space: `Game Project` remember on the command line a space means separate arguments. My advice is to never ever use a space in a path or filename in `c++` or `c`. – drescherjm Jan 09 '23 at 15:06
  • 1
    I would suggest skipping learning about makefiles and learn cmake instead. VSCode has some great extensions for cmake as well. I am making my suggestion because that makefile is not good. – sweenish Jan 09 '23 at 15:14
  • @drescherjm It was the quick fix in the vscode that it gives me. I know it wasn't gonna do anything with the Makefile but I tried it. – Foryxled_Dev Jan 09 '23 at 15:17
  • @sweenish Does cmake makes including libraries easier on vscode? – Foryxled_Dev Jan 09 '23 at 15:21
  • @sweenish I don't think this is an issue with make: I think it is probably the include/library paths on the `g++` command line. – JeremyP Jan 09 '23 at 15:24
  • Are you using the Makefile Tools extension for VSCode so that the include paths for Intellisense is setup for you? [https://marketplace.visualstudio.com/items?itemName=ms-vscode.makefile-tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.makefile-tools) – drescherjm Jan 09 '23 at 15:28
  • @drescherjm yes, I installed it a long time ago – Foryxled_Dev Jan 09 '23 at 15:35
  • @JeremyP That's likely true for this very specific issue, but if OP wants to go down this road (being VS Code and maybe more platform agnostic solutions), writing makefiles by hand is still not what I'd recommend. – sweenish Jan 09 '23 at 15:49
  • But to answer the other question I was asked, I would say that generally, yes, it's pretty straightforward to add a library in a cmake file. You can even get fancy with the spices and integrate a package manager like conan or vcpkg so that your build system can automatically acquire your libraries for you and free you up from needing to have them globally available on your system. – sweenish Jan 09 '23 at 15:55

1 Answers1

0

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.

JeremyP
  • 84,577
  • 15
  • 123
  • 161