# How to use "foreign" libraries in native nodes

**URL:** <https://forum.xod.io/t/how-to-use-foreign-libraries-in-native-nodes/230>\
**Category:** Uncategorized\
**Created:** [December 6, 2017, 11:56pm UTC](https://forum.xod.io/t/how-to-use-foreign-libraries-in-native-nodes/230 "2017-12-06T23:56:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![awgrover](https://avatars.discourse-cdn.com/v4/letter/a/74df32/32.png) [@awgrover](https://forum.xod.io/u/awgrover)\
**Post date:** [December 6, 2017, 11:56pm UTC](https://forum.xod.io/t/how-to-use-foreign-libraries-in-native-nodes/230/1 "2017-12-06T23:56:06Z")

</div>

How can I use libraries like “Midi Library” by Forty Seven Effects?

I can’t tell what the gcc include paths are, though it looks like only /opt/XOD IDE/resources/arduino-libraries (on linux).

So, my native node has

```
#include <MIDI.h>

```

which, of course, can’t be found.

(xod-client 0.16.0, linux ubuntu 14.04)

---

<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:** [December 7, 2017, 8:50am UTC](https://forum.xod.io/t/how-to-use-foreign-libraries-in-native-nodes/230/2 "2017-12-07T08:50:19Z")

</div>

Hello!

Yes, that’s a problem. XOD can’t hook up external libraries yet. The very ugly but technically possible ways right now:

- Put the library in `/path/to/ide/resources/arduino-libraries` and ask library consumers to do the same
- Concatenate `*.h` and `*.cpp` files of the library and paste the sheet right into `patch.cpp` 🙈

An adequate solution to the problem is yet to be found and implemented and it would be interesting to hear your opinion. The draft variants are:

- When compiling `-I`nclude directories of all XOD _libraries_ (projects). So one could a required library at the root of his project or a well-known subdirectory (e.g. ` __code__ `)
- Allow a library to have additional metadata to list GitHub links (repo + SHA1/tag) to the libraries required. The compiler then will download the code when required

The former approach potentially leads to `*.xodball` bloat, conflicts and duplication across libraries, however, it allows the ad-hoc creation of C++ libraries solely for XOD. The latter approach is a bit harder to understand for a newcomer, but more concise.

Both ways would deprive us the pipeline: Show code for Arduino → Copy/Paste to Arduino IDE → Compile/Upload there. And that’s not great.

---

<div class="post-metadata">

**Author:** ![awgrover](https://avatars.discourse-cdn.com/v4/letter/a/74df32/32.png) [@awgrover](https://forum.xod.io/u/awgrover)\
**Post date:** [December 10, 2017, 12:59am UTC](https://forum.xod.io/t/how-to-use-foreign-libraries-in-native-nodes/230/3 "2017-12-10T00:59:51Z")

</div>

> [@nkrkv](#):
>
> it would be interesting to hear your opinion

1. Treat the Arduino-IDE library location as a standard. “-I” that (e.g. on linux ~/Arduino/libraries). XOD could implement the mechanism to manage “arduino” libraries, but we have a fallback to the arduino-ide. Now XOD and Arduino-IDE share. This preserves the Show-Code-\>past-to-arduino-ide.

2. In libraries, it would be nice to develop native nodes that have multiple files, or that use some pre-written .cpp/.h files. On the XOD side, just “-I” the appropriate \_\_lib\_\_'s (someone should think about file-name collisions…). Obviously that can break the copy-to-arduino-ide thing. How important is that? How about generating a valid arduino-ide “project” instead?

3. xodball… I haven’t thought about the use-case for these. “package up a project to send to someone”? I don’t see how it affects that: a xodball doesn’t include all the library patches does it? I’m assuming that foreign libraries tend to belong to a xod library (or are #1’s).

4. foreign libraries in a project (or extra .h/.cpp’s). Seems like “-I” for your project would do the right thing. xodball would grab the whole project directory, and that seems to make sense.

> [@nkrkv](#):
>
> Allow a library to have additional metadata to list GitHub links (repo + SHA1/tag) to the libraries required. The compiler then will download the code when required

So, a package manager? 🙂 At least use a distributed (p2p) store (tahoe-lafs, ipfs), and don’t tie yourself too much to git. 😄 And, since you are doing that, let users use it to share projects (using git 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:** [December 10, 2017, 11:34am UTC](https://forum.xod.io/t/how-to-use-foreign-libraries-in-native-nodes/230/4 "2017-12-10T11:34:04Z")

</div>

Thanks!

Well, it would work to some extent. One of the targets we’re trying to achieve is zero-hassle libraries sharing. So if a library (say, `awgrover/midi`) uses a `MIDI` Arduino library that shouldn’t cause any additional steps to be required for a xoder who wants to install it.

It’s harder to explain that one should (a) install the XOD library and then (b) install the Arduino library.

Here’s yet another idea… What if we will introduce a `#pragma` directive to define Arduino library dependency?

```cpp
#pragma XOD require "https://github.com/FortySevenEffects/arduino_midi_library"

// ...

void evaluate(Context ctx) {
  // ...
}

```

Then at build step, we could scan for dependencies and download them automatically. This way we:

- save library users from downloading manually
- do not break the source code because an unknown `#pragma` is ignored by a compiler
- do not force anyone to bundle the Arduino library source code with XOD library

What do you think?

> [@awgrover](#):
>
> At least use a distributed (p2p) store (tahoe-lafs, ipfs), and don’t tie yourself too much to git.

Interesting, will read more about them

---

<div class="post-metadata">

**Author:** ![tobias](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@tobias](https://forum.xod.io/u/tobias)\
**Post date:** [July 28, 2018, 1:31pm UTC](https://forum.xod.io/t/how-to-use-foreign-libraries-in-native-nodes/230/5 "2018-07-28T13:31:40Z")

</div>

Hi there - did you make any progress on how to implement foreign libraries into XOD?

Best Tobias

---

<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:** [July 30, 2018, 9:44am UTC](https://forum.xod.io/t/how-to-use-foreign-libraries-in-native-nodes/230/6 "2018-07-30T09:44:37Z")

</div>

Oh, can’t believe eight months past since the beginning of this topic. The related issue is on GitHub already ([#1218](https://github.com/xodio/xod/issues/1218)) and we plan to implement it 0.24.0 or 0.25.0.

---

<div class="post-metadata">

**Author:** ![brusher\_ru](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/brusher_ru/32/12_2.png) [@brusher\_ru](https://forum.xod.io/u/brusher_ru)\
**Post date:** [October 18, 2018, 2:46pm UTC](https://forum.xod.io/t/how-to-use-foreign-libraries-in-native-nodes/230/7 "2018-10-18T14:46:01Z")

</div>

Finally, it solved in the 0.24.0 🙂
