William J Bagshaw
William J Bagshaw

Reputation: 565

Using eclipse to edit C++ code. How do I automatically include a default header file without editing all the code

I have some existing C++ code that I am editing under eclipse Oxygen. It is reporting errors in the IDE because the original project under a different IDE was configured to include a specified default header file automatically. How can I do this in eclipse.

Not asking how to change a template for a new file.

Do not know how to use -include option as I do not have a make file. Using -include is described in "Is there any way to include a header file in all C or CPP file automatically? "

I cannot see a way to do this under Preferences > C/C++ Build > Settings. enter image description here

Upvotes: 0

Views: 1481

Answers (2)

majji
majji

Reputation: 11

If I understand correctly, you are not building you code with Eclipse but just using the editor, and the C++ project was probably created with a type Makefile project without any Toolchain. In that case I would suggest the following ...

To configure the include path in Eclipse CDT without any toolchain :

  • Open the Properties dialog for your project :
    In Project Explorer panel, right-click on your project and in the context menu select Properties.
  • Go to Paths and Symbols :
    In dialog Properties, select C/C++ General > Paths and Symbols > Includes > Languages = C++
  • Add the Include directory that contains the header file.
  • Rebuild the Index :
    In _Project Explorer, right-click and select Index > Rebuild.

Upvotes: 0

majji
majji

Reputation: 11

To configure the include path in Eclipse CDT :

  • Open the Properties dialog for your project :
    In Project Explorer panel, right-click on your project and in the context menu select Properties.
  • Go to the Build Settings for Compiler :
    In dialog Properties, select C/C++ Build > Settings > Tool Settings > Compiler > Includes
  • Add an Include file (-include) :
    • You may select Configuration: [All configurations] to add the -include option both in Release and Debug mode.
    • You may create a variable in C/C++ Build > Build Variables to use it in the file name (e.g.: "${INSTALL_HOME}/include/global.h")

Upvotes: 1

Related Questions