Jaikaran saini
Jaikaran saini

Reputation: 39

how to link and include c++ headers from different directory in vscode

I am new in programming I am using vscode in windows and compiling via Mingw 64. I am requesting an answer to this question after tried of trying for days. I googled it many times. here is how my project tree looks. please help me include and link libA to libB and common.h to all cpp files and libA and libB to to main.cpp. Please answer.

project
|---lib
|   |---libA
|   |   |---header1.h
|   |   |---header1.cpp
|   |
|   |---libB
|       |---header2.h
|       |---header2.cpp
|---common
|   |---common.h
|   |---common.cpp
|---main.cpp

Upvotes: 3

Views: 13169

Answers (2)

Raghvendra Rao
Raghvendra Rao

Reputation: 156

You should use the relative path in #include.

For example to import header1 use -#include "./lib/header1.h" and to import common use #include "./common/common.h"

Upvotes: 1

From VSCode, you can right click on the headers and select Copy Path. That should work when including headers from anywhere on your computer.
As for the .cpp files, you could use relative paths to the directory you're compiling in, when compiling and linking the files, or use the -I option when compiling with g++.
This might help.

Upvotes: 3

Related Questions