Internal includes instead of global ones – EasyHack

In every C/C++ source code file, we use header files to put declarations of functions, data types, class, macro and other relevant things inside it. These files have the extension of .h (for C) and .hxx (for C++).

We have different header types: internal and global includes. You can find some of the header files in many places. For example, in LibreOffice we have several modules that many other modules depend on them. Here, we focus on the VCL module. For the global includes, they are placed inside include/ folder, and for internal headers of VCL module, the include files are put inside include/vcl/.

On the other hand, not all the VCL headers are beneficial outside the VCL module. In this case, it is preferred that these include files are put inside the vcl/ folder. Usually, those header files should be inside vcl/inc folder.

As an example, we have the header include/vcl/salnativewidgets.hxx file which have declarations that are not used outside vcl/. In this case, we can put the declarations inside vcl. The suggested place is vcl/inc/nativewidgets.hxx.

Finding Internal Includes

As suggested in the bug report, one trick is to look at the class/function declaration. If it doesn’t have a SAL_DLLPUBLIC attribute decorating it, there is good chance that you can move it to the private headers, and in this case, vcl/inc/ folder.

Other than that, you should use the include syntax <…>. For example, if you have created vcl/inc/nativewidgets.hxx, then the include syntax would be:

#include <nativewidgets.hxx>

This is because the file is not exactly next to the cxx file. You can read more here:

Final Notes

EasyHacks are good starting points for someone who wants to start LibreOffice development. This specific issue for improving header files of VCL is avaiable as tdf#97228 in TDF’s Bugzilla. To understand how to start LibreOffice development, you can refer to our getting involved page in the TDF Wiki, or our video tutorial for getting started with LibreOffice development.