How to include (make calls to) non-JUCE code

DISCLAIMER:

Hello everyone. First, all the requisite apologies for being new to JUCE and perhaps not the most advanced C++ programmer in the world. My immediate goal is seemingly simple, but so far elusive. And yes, I did spend over an hour searching the forum for an answer before I posted this topic, but have found nothing (so far) that directly answered my question. So here goes…

SUMMARY OF QUESTION:

What is the best practice for including external code within a JUCE application? What am I doing wrong here?

DETAILS:

I have exported the PlayingSoundFiles tutorial to MS VS 2017 Express and I want to make calls to existing (non-JUCE) code. I’ve tried “Add Existing Files” in ProJucer which results in my header and source files showing up in the VS project, however when I try to #include the (.h) header file I get an error “cannot open source file.” I’ve tried #include with just the filename, as well as with the full path, and neither works.

I’ve attempted the #include statements in two places:

  1. inside “JuceHeader.h” under the other include statements for JUCE classes
  2. inside “AppConfig.h” under the section called BEGIN USER CODE

I have the same problem from either location. Please note that these header and source files work just fine in a new (non-JUCE-created) VS 2017 Express project when I “add existing files” from within VS.

Also worth noting… I tried to call my class to create an object just in case the code was magically included elsewhere without my knowledge, but that also failed with the class name unrecognized.

POSTSCRIPT:

Thanks in advance for any and all advice.

-David

1 Like

When you “Add Existing Files” via the Projucer, it’s really adding references to those files and telling Visual Studio where the original file is. However, the compiler itself doesn’t know the location of those files.

You’ll need to specify to the compiler the location(s) of the files you’re trying to include. With JUCE this can be done in the Projucer via the “Header Search Paths” option (click on your Visual Studio exporter in Projucer and you can find the header search paths option available for each configuration Debug & Release).

When you include files that aren’t in the same folder as your source you should use <>. So for example if you have some header file in C:\somefolder\include\module\foobar.h, you could set the Projucer’s header search paths to C:\somefolder\include and include it by writing #include <module/foobar.h>.

When you “Add Existing Files” directly from Visual Studio it may be copying them into your project (I’m not very familiar with VS though), which could be why #include "someheader.h" would work there but not when using Projucer.

Hope that helps!

3 Likes

That did it. Thank you, Alassandro!

1 Like