Get path to location of PluginProcessor.cpp

Hi There,

I need to have my plugin load a file that is located in the same directory as my PluginProcessor.cpp.

I tried getting the path to the file by using File::getCurrentWorkingDirectory(), but that just returns "/", which appears to be the root directory of the system.

Is there any way to generate the path from the root to the PluginProcessor.cpp? I want to be able to generate the path from within the code so that other developers I’m collaborating with can just run it and don’t need to reset the path each time they load the project.

If you’re using CMake, you can add a compile definition for this.

Note that this strategy will not work for releasing/deploying.

Oh nice yeah I am using CMake, that’ll work, thanks!!

What’s the strategy for deploying? Maybe package the file as a binary, maybe have the plugin take in the file during compilation/installation and re-write to a shared directory somewhere?

The best way would be to bake this data into the compiled binary, using juce’s provided juce_add_binary_data function. Trying to keep the data files separate is possible, but greatly increases the number of problems for you to solve.

1 Like

In your source code you can also use a standard define __FILE__:

But like Ben pointed out, the source folder won’t be present on the users machine.

Yeah I got it working nicely for development collaboration using CMake add_compile_definitions but will likely need to roll it up into the binary for deployment.

Thanks for the help!!