Including juce_TargetPlatform.h from a C file


#1

I have built some juce modules which are compiled with the C compiler. For example, the vf_sqlite module is provided as vf_sqlite.c, to be compiled with the C compiler (since SQLite is written in C).

I would like to be able to include only juce_TargetPlatform.h from within these files so that I can get access to those wonderfully convenient platform macros. The problem is:

namespace JuceDummyNamespace {}

If we could wrap that in “#ifdef __cplusplus” or something it would be great, although in your comment you said you wanted to generate an error if you attempt to build with a C compiler. Maybe we could move the namespace into a separate file:

juce_TargetPlatform.hpp

//...
namespace JuceDummyNamespace {}
#include "juce_TargetPlatform.h"

juce_core.h would include “juce_TargetPlatform.hpp” instead, and I could include “juce_TargetPlatform.h”.

Although I’m unsure if #include <CoreFoundation/CoreFoundation.h> works from a C source file.


#2

This workaround seems to do the trick although I would hate to rely on it:

#define namespace
static void JuceDummyNamespace ()
#define JuceDummyNamespace
#include "modules/juce_core/system/juce_TargetPlatform.h"

#3

TBH there’s no reason why that line needs to be in juce_TargetPlatform… In fact now that it’s all modularised, it’d probably be more appropriate for it to be in juce_core.h instead, and to not clutter juce_TargetPlatform with it.