Including a header file in a generated file
If you need to include an external C/C++ header file in a generated C++ file, do the following:
- Select the model element in the Project Explorer that translates into the generated C++ file where you want to include the file (for example, a class or capsule.)
- Right-click and choose Show Code View to make the Code view visible.
- Click one of the tabs in the Code view. Click "Header Preface" if you want to add the include to the header file, and click "Implementation Preface" if you want to include it to the implementation file.
- Type the #include in the Code view. If you want more space you can click Show Source in Editor to open the code snippet in the Code editor instead. The Code editor can either show one specific code snippet, or all code snippets for the element. See Working with multiple code snippets in the Code Editor.
As always when editing C++ code using the Code view or Code editor, load the generated source (right-click in the editor and choose the command from the context menu or press Ctrl + Shift + L). By doing so, the generated C++ file gets loaded into the Code view or Code editor and all editing features of Eclipse CDT become available. If you edit without doing this step, some editing features are missing.