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.
User avatar
DeepSOIC
Posts: 6652
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

BaseExport causing parse errors in Qt Creator

Postby DeepSOIC » Tue May 07, 2019 9:53 pm

Hi.
BaseExport and similar things are confusing my new QtCreator.
GuiExport problem.png
GuiExport problem.png (63.22 KiB) Viewed 210 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
Posts: 6652
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: BaseExport causing parse errors in Qt Creator

Postby DeepSOIC » Tue May 07, 2019 11:59 pm

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
Posts: 2906
Joined: Wed Oct 05, 2011 7:36 am

Re: BaseExport causing parse errors in Qt Creator

Postby ickby » Wed May 08, 2019 7:01 am

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
Site Admin
Posts: 14451
Joined: Thu Feb 19, 2009 10:32 am

Re: BaseExport causing parse errors in Qt Creator

Postby wmayer » Wed May 08, 2019 9:56 am

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
Site Admin
Posts: 14451
Joined: Thu Feb 19, 2009 10:32 am

Re: BaseExport causing parse errors in Qt Creator

Postby wmayer » Thu Jul 18, 2019 5:13 pm

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.