Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include header files with similar names in C++ project

I am using an external library in my C++ program. This library has a fie named "Common.h". Without knowing about this file, I also created a "Common.h" in my program. Using the compiler flag "#pragma once" in the headers I could ensure that both the files can be included in the compilation. However, I realized that when I call my "Common.h" in my program, the preprocessor wrongly includes the "Common.h" from the external library which breaks the compilation. Is there any option like "namespace" which allows me to include the correct file. I find it really difficult, as we may not (indeed need not) aware about all the files in the external library.

like image 707
Soo Avatar asked Jan 05 '23 20:01

Soo


1 Answers

Usually program has several so called include paths to look for header files. It seems you have included both path to directory containing your "Common.h" file, as well as library headers directory. As for me, perfect solution seems to remove include path of library files and use explicit relative path, as:

#include "mylib/include/Common.h"
like image 182
Andrei R. Avatar answered Jan 29 '23 13:01

Andrei R.