Error: macro name must be an identifier

I’m hitting this error and finding it very hard to work out what caused it.
This is a CMake project building on macOS 13.4

The project version is set to “0.1.0”. I’m not sure if that is a red herring or a clue.

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -D0.1.0 -DCOMPANY_NAME_STRING="\"Prospeech Technologies\"" -DDEBUG=1 -DJUCE_APPLICATION_NAME_STRING="" -DJUCE_APPLICATION_VERSION_STRING="" -DJUCE_GLOBAL_MODULE_SETTINGS_INCLUDED=1 -DJUCE_MODAL_LOOPS_PERMITTED=1 -DJUCE_MODULE_AVAILABLE_juce_core=1 -DJUCE_MODULE_AVAILABLE_juce_data_structures=1 -DJUCE_MODULE_AVAILABLE_juce_events=1 -DJUCE_MODULE_AVAILABLE_juce_graphics=1 -DJUCE_MODULE_AVAILABLE_juce_gui_basics=1 -DJUCE_MODULE_AVAILABLE_juce_gui_extra=1 -DJUCE_STANDALONE_APPLICATION=1 -DJUCE_TARGET_HAS_BINARY_DATA=1 -DJUCE_USE_CURL=0 -DJUCE_WEB_BROWSER=0 ....
In file included from <built-in>:485:
<command line>:1:9: error: macro name must be an identifier
#define 0.1.0 1
        ^
1 error generated.

@reuk any clues or things I can try to debug or solve it?

That flag, passed to the compiler, will be the problem. I’m not sure where that could be coming from. The first thing I’d check is that the version is set in juce_add_plugin or equivalent, instead of target_compile_definitions.

Yes, my assumption also.

The version is set in the CMake project command. However I get the same issue if I set it in juce_add_gui_app.

No version is set in target_compile_definitions

target_compile_definitions was a clue. It seems that clang-format added a space in front of these definitions which I think caused the issue.

        JUCE_APPLICATION_NAME_STRING= "$<TARGET_PROPERTY:${PROJECT_NAME},JUCE_PRODUCT_NAME>"
        JUCE_APPLICATION_VERSION_STRING= "$<TARGET_PROPERTY:${PROJECT_NAME},JUCE_VERSION>")

Fixed now thank you.

3 Likes

Yep, I was struggling with this a week or so back. No spaces around the equal sign!

A direct contravention of the JUCE coding style guide :grin:

1 Like

Thanks Adam, this just saved my butt. Shakes fist at CLion