BaseExport causing parse errors in Qt Creator

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

BaseExport causing parse errors in Qt Creator

Post by DeepSOIC »

Hi.
BaseExport and similar things are confusing my new QtCreator.
GuiExport problem.png
GuiExport problem.png (63.22 KiB) Viewed 992 times
Happens to just about every header file in FreeCAD.

Interestingly, in old Qt Creator, it wasn't much of a problem: it would just underline them, saying "skipping identifier BaseExport" or something.

Is there an easy fix for this? I tried adding add_definitions(-DBaseExport= ) to CMakeLists.txt, that fixed the parsing problem but created build errors.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: BaseExport causing parse errors in Qt Creator

Post by DeepSOIC »

temporarily adding #include <FCConfig.h> to the top of the file makes the parser happy. Fine, as long as I don't forget to clean that out when committing.
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: BaseExport causing parse errors in Qt Creator

Post by ickby »

I remember vaguely that I had such a problem before. The thing was that the precompiled.h files, which define the macros, use some freecad specific defines to guard the macro definitions. When those defines are not known to the IDE it does not find the definitions. For me it helped to change the IDE settings to set the correct "define"
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: BaseExport causing parse errors in Qt Creator

Post by wmayer »

Interestingly, in old Qt Creator, it wasn't much of a problem: it would just underline them, saying "skipping identifier BaseExport" or something.
QtCreator provides a lot of plugins and for some years it uses the clang compiler to detect syntax errors and the like. If am not not totally wrong then the plugin name is ClangCodeModel which I had to disable to get rid of the warnings. Maybe you did this too with your old version and thus you didn't see all the warnings.
Is there an easy fix for this? I tried adding add_definitions(-DBaseExport= ) to CMakeLists.txt, that fixed the parsing problem but created build errors.
I haven't found one when I searched for a solution.

FYI, the macros BaseExport, AppExport, GuiExport, ... are needed for Windows because when creating a dll you must tell the linker which symbols must be exported. For compilers on Windows the macro expands to __declspec(dllexport) for the target that creates a .dll and __declspec(dllimport) when a target uses an existing library.
So, you mustn't simply add a definition to the CMakeLists.txt file because you will mess up the definitions inside the source code.
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: BaseExport causing parse errors in Qt Creator

Post by wmayer »

Here is a way to suppress the clang error messages about the export macros:
https://doc.qt.io/qtcreator/creator-pro ... ng-defines

You follow the steps to import an existing project and call it e.g. FreeCAD. This will create the file FreeCAD.config and there you can add the lines:

Code: Select all

#define BaseExport
#define AppExport
#define GuiExport
...
I wonder where there is a way to also tell QtCreator's clang code model to ignore the export macro when loading it as a regular project.
Post Reply