# Best way to share code from plugin project

**URL:** <https://forum.juce.com/t/best-way-to-share-code-from-plugin-project/29431>\
**Category:** General JUCE discussion\
**Created:** [September 14, 2018, 1:00pm UTC](https://forum.juce.com/t/best-way-to-share-code-from-plugin-project/29431 "2018-09-14T13:00:02Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![DEADBEEF](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@DEADBEEF](https://forum.juce.com/u/DEADBEEF)\
**Post date:** [September 14, 2018, 1:00pm UTC](https://forum.juce.com/t/best-way-to-share-code-from-plugin-project/29431/1 "2018-09-14T13:00:02Z")

</div>

Hi,

I’ve a current project where I created a plugin.  
Now I will develop an other plugin but only the GUI will change and some values in the PluginProcessor.

I would like to avoid rewritting everything so I’m looking for the most elegant solution to produce 2 different plugins from the same code.

The only way I’ve found for the moment is to create 2 projucers for each skin. But I would have to modify both of them if I found a bug in the common code.

Is it possible to create a library from a common project then use it into 2 projucers where each of them will use specific gui. So the `PluginProcessor` and `PluginEditor` will inherit from the `CommonPluginProcessor` and `CommonPluginEditor` ?

That way I will end up with 3 projucers, one for the commun backend code, and 2 other for custom skin and specific backend custom code.

---

<div class="post-metadata">

**Author:** ![ImJimmi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/imjimmi/32/10843_2.png) [@ImJimmi](https://forum.juce.com/u/ImJimmi)\
**Post date:** [September 14, 2018, 1:13pm UTC](https://forum.juce.com/t/best-way-to-share-code-from-plugin-project/29431/2 "2018-09-14T13:13:12Z")

</div>

I reuse a lot of code across my projects and so I made myself a small JUCE module that holds all my cross-project code (mostly look-and-feel and filters).

Copy the structure of the existing JUCE modules to setup your own module - it’s fairly straight forward if you look through it carefully!

---

<div class="post-metadata">

**Author:** ![DEADBEEF](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@DEADBEEF](https://forum.juce.com/u/DEADBEEF)\
**Post date:** [September 14, 2018, 1:52pm UTC](https://forum.juce.com/t/best-way-to-share-code-from-plugin-project/29431/3 "2018-09-14T13:52:34Z")

</div>

So, if I understood well you have a custom projucer where you create your classes. Then you packages them in a folder with the right structure to create a module then import this module inside your project. Right?

---

<div class="post-metadata">

**Author:** ![ImJimmi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/imjimmi/32/10843_2.png) [@ImJimmi](https://forum.juce.com/u/ImJimmi)\
**Post date:** [September 14, 2018, 2:06pm UTC](https://forum.juce.com/t/best-way-to-share-code-from-plugin-project/29431/4 "2018-09-14T14:06:23Z")

</div>

> [@DEADBEEF](#):
>
> custom projucer

Not sure what you mean by ‘custom projucer’, I assume you mean a custom projucer (`.jucer`) project? If so, you don’t need a project to create a module - just all your source code in the right file structure (however I do have a testing project in my module).

But yes, I have a folder on my desktop called “MyAwesomeJUCEModule” which I then add to the modules list of all my JUCE projects. If I need to fix or add something for all the projects I only need to make changes in the one place.

```auto
MyModule/
+---Filters/
| +---CustomFilters.cpp
| +---CustomFilters.h
+---GUI/
| +---CustomLookAndFeel.cpp
| +---CustomLookAndFeel.h
+---MyModule.cpp
+---MyModule.h

```

---

<div class="post-metadata">

**Author:** ![DEADBEEF](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@DEADBEEF](https://forum.juce.com/u/DEADBEEF)\
**Post date:** [September 14, 2018, 2:15pm UTC](https://forum.juce.com/t/best-way-to-share-code-from-plugin-project/29431/5 "2018-09-14T14:15:28Z")

</div>

By “custom projucer” I meant a project to test your source. So yes it could be optional.

Thank you for the details. I will do that.

---

<div class="post-metadata">

**Author:** ![khuasw](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/khuasw/32/4698_2.png) [@khuasw](https://forum.juce.com/u/khuasw)\
**Post date:** [September 14, 2018, 3:15pm UTC](https://forum.juce.com/t/best-way-to-share-code-from-plugin-project/29431/6 "2018-09-14T15:15:19Z")

</div>

If the two projects share a lot of common codes, then as [Im\_Jimmi](https://forum.juce.com/u/Im_Jimmi) suggested, it’s better to drop them into a new module.  
If it’s really just one or two headers or cpps - I’ve tried including a header from the other project’s directory but that’ll run into JUCE AppConfig.h conflicts. A simple and git-friendly workaround is to create a symbolic link across the source directories.

---

<div class="post-metadata">

**Author:** ![DEADBEEF](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@DEADBEEF](https://forum.juce.com/u/DEADBEEF)\
**Post date:** [September 14, 2018, 3:27pm UTC](https://forum.juce.com/t/best-way-to-share-code-from-plugin-project/29431/7 "2018-09-14T15:27:50Z")

</div>

Ah yeah, thanks for the workaround and your insight.

But since I’ve like 90% of the project that is shared I will try the @Im_Jimmi solution.

---

<div class="post-metadata">

**Author:** ![ImJimmi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/imjimmi/32/10843_2.png) [@ImJimmi](https://forum.juce.com/u/ImJimmi)\
**Post date:** [September 14, 2018, 3:28pm UTC](https://forum.juce.com/t/best-way-to-share-code-from-plugin-project/29431/8 "2018-09-14T15:28:52Z")

</div>

> [@DEADBEEF](#):
>
> the @Im\_Jimmi solution.

I am totally on board with this being called “the Im\_Jimmi solution” from now on! 😉

---

<div class="post-metadata">

**Author:** ![PeterRoos](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@PeterRoos](https://forum.juce.com/u/PeterRoos)\
**Post date:** [September 14, 2018, 3:39pm UTC](https://forum.juce.com/t/best-way-to-share-code-from-plugin-project/29431/9 "2018-09-14T15:39:31Z")

</div>

What’s wrong with including files/folders like this in your Juce projects?

```
#include "../../Shared/ (etc)
```

---

<div class="post-metadata">

**Author:** ![DEADBEEF](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@DEADBEEF](https://forum.juce.com/u/DEADBEEF)\
**Post date:** [September 14, 2018, 4:13pm UTC](https://forum.juce.com/t/best-way-to-share-code-from-plugin-project/29431/10 "2018-09-14T16:13:27Z")

</div>

Yes it’s a good idea too.  
But I would have to add this line in multiple file in addition to `#include "../JuceLibraryCode/JuceHeader.h"`.  
If I create a custom module, I add it in the projucer and adding `#include "../JuceLibraryCode/JuceHeader.h"` is enough.  
But if my shared code wouldn’t be juce related I would definitely use what you say.

---

<div class="post-metadata">

**Author:** ![bwall](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/bwall/32/618_2.png) [@bwall](https://forum.juce.com/u/bwall)\
**Post date:** [September 14, 2018, 8:06pm UTC](https://forum.juce.com/t/best-way-to-share-code-from-plugin-project/29431/11 "2018-09-14T20:06:38Z")

</div>

I just have a “Common” folder in my main projects folder. Any shared code is there and projects use the appropriate “includes”. Simple, and easy to maintain.
