# Different syntax for #include

**URL:** <https://forum.arduino.cc/t/different-syntax-for-include/38025>\
**Category:** Development\
**Created:** [November 17, 2010, 12:30pm UTC](https://forum.arduino.cc/t/different-syntax-for-include/38025 "2010-11-17T12:30:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [November 17, 2010, 12:30pm UTC](https://forum.arduino.cc/t/different-syntax-for-include/38025/1 "2010-11-17T12:30:35Z")

</div>

Hi,

Just a general question about #include statements. Having browsed through 1000's of lines of code recently, there seems to be three different ways of including a library....

Method 1.....

```cpp
#include "my_lib1.h"

```

Method 2......

```cpp
#include <my_lib2.h>

```

Method 3.....

```cpp
extern "C" {
  #include <my_lib3.h.h>
}

```

Qu1 - What's difference (if any) between these 3 methods? (I've looked on the forum but couldn't find any answers)  
Qu2 - When writing your own library, why is it necessary to include reference to the header file for itself?  
Qu3 - When writing a library that includes other librarys should the include go in the .h file, the .cpp file, or both?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [November 17, 2010, 3:16pm UTC](https://forum.arduino.cc/t/different-syntax-for-include/38025/2 "2010-11-17T15:16:55Z")

</div>

1. The difference between the first two (" vs. \<) has to do with where the include files are looked for. One indicates that the include file is local (") while the other indicates that the include file is in a standard location (\<,\>).

In general, compilers seem to blur that distinction.

The 3rd version is how to include a header file for C code in a C++ file, to avoid the name-mangling that C++ performs/expects.

1. The header file for the class needs to be included in the source file for the class, so the compiler knows what functions should be present, and what the arguments to each function are.

2. If the definition of the library is needed in the class definition, the header file should included in the .h file. If not, it should be included in the .cpp file (and the sketch).

If the header file is included in the .h file, it is not necessary to include it in the .cpp file, too.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [November 17, 2010, 4:21pm UTC](https://forum.arduino.cc/t/different-syntax-for-include/38025/3 "2010-11-17T16:21:31Z")

</div>

Thanks Paul!

---

<div class="post-metadata">

**Author:** ![Coding\_Badly](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Coding\_Badly](https://forum.arduino.cc/u/Coding_Badly)\
**Post date:** [November 17, 2010, 6:23pm UTC](https://forum.arduino.cc/t/different-syntax-for-include/38025/4 "2010-11-17T18:23:13Z")

</div>

> In general, compilers seem to blur that distinction.

Naw. The difference is the person using it. Often "." is present in the include path which makes the two identical.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 7:54pm UTC](https://forum.arduino.cc/t/different-syntax-for-include/38025/5 "2021-05-06T19:54:20Z")

</div>


