# Adding header files to a project or library

**URL:** <https://forum.xod.io/t/adding-header-files-to-a-project-or-library/519>\
**Category:** Uncategorized\
**Created:** [February 20, 2018, 2:44am UTC](https://forum.xod.io/t/adding-header-files-to-a-project-or-library/519 "2018-02-20T02:44:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [February 20, 2018, 2:44am UTC](https://forum.xod.io/t/adding-header-files-to-a-project-or-library/519/1 "2018-02-20T02:44:16Z")

</div>

How do we package include files with a project or library? Is there a better place to copy them than \<user\_folder\>\AppData\Local\Programs\xod-client-electron\resources\arduino-libraries? That’s where I found the LCD headers & adding IRremote headers there allowed me to use them. I haven’t been able to get it to work with header files in the project.

---

<div class="post-metadata">

**Author:** ![nkrkv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/nkrkv/32/8_2.png) [@nkrkv](https://forum.xod.io/u/nkrkv)\
**Post date:** [February 20, 2018, 12:34pm UTC](https://forum.xod.io/t/adding-header-files-to-a-project-or-library/519/2 "2018-02-20T12:34:17Z")

</div>

No, unfortunately. Many things are tied to the process of transpiling the whole program to a single sketch file. Including arbitrary library code in it would be a nightmare to implement and maintain.

A better decision that pops up in my mind is a special pragma directive:

```cpp
#pragma XOD require "https://github.com/z3t0/Arduino-IRremote"

struct State { ... };

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
  ...
}

```

Then when XOD sees the `require` pragma it will automatically download the code to a well-known location and any library user can straightly use the node.

The feature is yet to be implemented.

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [February 20, 2018, 3:58pm UTC](https://forum.xod.io/t/adding-header-files-to-a-project-or-library/519/3 "2018-02-20T15:58:38Z")

</div>

I would prefer an option that didn’t require internet access. Maybe allow URL or included with the project?

In Arduino IDE, using \<header.h\> implies to look in system files while “header.h” implies to look in code folder (or maybe that is reversed…). XOD seems to treat both the same.

---

<div class="post-metadata">

**Author:** ![nkrkv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/nkrkv/32/8_2.png) [@nkrkv](https://forum.xod.io/u/nkrkv)\
**Post date:** [February 21, 2018, 9:59am UTC](https://forum.xod.io/t/adding-header-files-to-a-project-or-library/519/4 "2018-02-21T09:59:06Z")

</div>

The difference between `#include <header.h>` and `#include "header.h"` is up to compiler decision (GCC). It is a level lower than Arduino IDE or XOD. In practice, it only varies file lookup order.

> [@gweimer](#):
>
> I would prefer an option that didn’t require internet access

I see. But when you install a library you access internet anyway. The C++ library may be installed at the same time.

Let’s imagine the C++ libraries are installed into XOD workspace, not into `AppData\Local\Programs\...`. In this case, if you’d like to replicate the same setup across many machines (e.g., in a school class), you’d have to install everything necessary once, and then simply copy the workspace directory to each PC even without network access.

Will it work for you?

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [February 21, 2018, 2:58pm UTC](https://forum.xod.io/t/adding-header-files-to-a-project-or-library/519/5 "2018-02-21T14:58:30Z")

</div>

That would be fine. I have to copy the AppData avrtools and `XOD\ __lib__ ` folders anyway to be able to use the software without internet access. I was just worried that the solution you were suggesting would require internet access any time it was encountered. Even your suggestion would work if it checked locally somewhere to see if it already existed before hitting the internet. I’m not sure how you would handle getting updates, though…

It would be nice if the include files could be included in the library. Maybe a ` __header__ ` folder whose contents gets copied to the system location (or XOD workspace) where it is needed when you Add Library? I would still have to manually copy it for use without internet access, but it provides a method to have everything needed by a library packaged in the library. The down-side of providing a URL to pull the headers is the URL could go away or its contents change. Maybe allow Add Library from local file option???

---

<div class="post-metadata">

**Author:** ![nkrkv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/nkrkv/32/8_2.png) [@nkrkv](https://forum.xod.io/u/nkrkv)\
**Post date:** [February 22, 2018, 8:21am UTC](https://forum.xod.io/t/adding-header-files-to-a-project-or-library/519/6 "2018-02-22T08:21:38Z")

</div>

> [@gweimer](#):
>
> I was just worried that the solution you were suggesting would require internet access any time it was encountered.

Yeah, the system would download libs once and not touch network if the Arduino library is here already.

> [@gweimer](#):
>
> I’m not sure how you would handle getting updates, though…
> 
> …The down-side of providing a URL to pull the headers is the URL could go away or its contents change.

Kill the `xod/ __ardulib__ /IRremote` and upload again to force the latest master to be installed. Alternatively, use

```cpp
#pragma XOD require "https://github.com/z3t0/Arduino-IRremote" "v2.4.0"
// or
#pragma XOD require "https://github.com/z3t0/Arduino-IRremote" "96186317b251c04da595159402f80538c0be5eed"

```

To enforce a specific Git tag or commit.

Indeed, the repository may be deleted by its author, but doesn’t that mean he messed up the whole Arduino community? I mean that should be very rare. And even so, you can ensure the code will be “always” out there by forking the original repo with a single click to, say, `"https://github.com/gweimer/Arduino-IRremote"` and use this URL.

> [@gweimer](#):
>
> It would be nice if the include files could be included in the library.

Yep, it’s tempting, but at the moment I see no quick-to-implement way to serialize all C++ library files properly into xodballs. I’m not sure it is a proper direction. Most major ecosystems do not carry dependencies with projects, they rely on libraries in the cloud hoping they are always there (JavaScript — NPM, Python — Pip, Ruby — Gems, Haskell — Cabal, etc).

---

<div class="post-metadata">

**Author:** ![nkrkv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/nkrkv/32/8_2.png) [@nkrkv](https://forum.xod.io/u/nkrkv)\
**Post date:** [May 17, 2018, 5:06pm UTC](https://forum.xod.io/t/adding-header-files-to-a-project-or-library/519/7 "2018-05-17T17:06:30Z")

</div>

Issued on GitHub: [https://github.com/xodio/xod/issues/1218](https://github.com/xodio/xod/issues/1218)
