how to disable pic32-g++ duplicate 'const' errors?

Asked by ntronics at 10:27 on 24 Aug 2017.

I have encountered duplicate 'const' compilation errors with uGFX graphics library. The library is written in C language and uses duplicate const declarations like:

const char const keycap; const char const sendkey;

pic32-g++ fails to compile it. Is there any way to suppress this type of compilation error? I tried "Suppress warning" and "Enable all warnings" UECIDE options with the same result.

I've spent some on researching gcc compilation flags. '-Wduplicate-decl-specifier' enables warnings for duplicate consts. This option is implicitly enabled only when '-Wall' option is enabled (UECIDE "Enable all warning"). But if I understand this correctly all warnings are inhibited by '-w' option (UECIDE "Suppress warnings"). Hence the compiler should ignore duplicate consts when "Supress warnings" is enabled, but in reality it exits on duplicate const error. Can you please help me to understand what am I doing wrong? How to disable pic32-g++ duplicate const errors?

Sign up or log in for live updates and to post messages.

If it's an error then messing with warning settings won't change anything. The only one that could is the one that treats all warnings as errors (-Werror), but if it's already an error then you can't hide it.

And it is correct, it is an error. As shown in this StackExchange answer.

In C99 it is valid to repeat const like that. But in C++, you cannot repeat it.

I am not sure what exactly the second const is trying to achieve there. Personally I would just delete it.

However I also wouldn't use uGFX on PIC32, but DisplayCore instead.

Posted 24 Aug 2017, 10:40, 0 votes
matt
Rating: 3

Thank you for clarification. I want to avoid modifying uGfx source as it may become a nightmare on library update. DisplayCore library looks very nice, but it's missing Virtual Keyboard and Graph widgets which I was hoping to use.

Does ARM compiler have similar issues? I'm thinking of trying Teensy 3.2 instead of ChipKit Max32 board.

Posted 24 Aug 2017, 13:08, 0 votes
ntronics
Rating: 0

When exactly do you get the error? What file is it compiling at the time?

Posted 24 Aug 2017, 13:09, 0 votes
matt
Rating: 3

You should only see that error if the keyboard's header file is included in a c++ file, which it shouldn't be.

Posted 24 Aug 2017, 13:11, 0 votes
matt
Rating: 3

Yes the keyboard's header file is included in the main sketch. This is needed to customise keyboard's layout. I'm afraid this is unavoidable because uGfx library does not provide high level functions to achieve this. I've attached a project that demonstrates this error.

Posted 24 Aug 2017, 14:00, 0 votes
ntronics
Rating: 0

So you should create a C file and include the header in that instead, along with your custom configuration. Then call whatever you need in that file from your sketch. Just point to anything you want in that C file with extern.

Posted 24 Aug 2017, 14:03, 0 votes
matt
Rating: 3

Basically anything that uses GVSpecialKey or any variables of that type will have to be in functions in the C file. You can't use GVSpecialKey in C++.

Changing to a different board or compiler would be unlikely to change that - it's the rules of C++.

Posted 24 Aug 2017, 14:14, 0 votes
matt
Rating: 3

Matt, thank you very much for helping with this problem. The sketch finally compiles after moving C language declarations into a separate .c file!

Posted 24 Aug 2017, 14:34, 0 votes
ntronics
Rating: 0

Excellent. I don't quite know why the powers that be decided that what is valid in C would be invalid in C++, since C++ is supposed to be a super-set of C...

Posted 24 Aug 2017, 14:35, 0 votes
matt
Rating: 3

This site uses cookies to maintain your current login session and improve your browsing experience. By continuing to use this site you agree to the placing of these cookies on your computer or device.

About cookies | Close this popup