0

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

2 Answers2

1

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")
majji
  • 11
  • 2
0

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.
majji
  • 11
  • 2
  • The source is expecting an include file to be automatically included. There is no explicit #include in the code. (Not ideal I know) I do not know how to add this file. There may be a way of prefixing all files with some code. I do not know how to do this. – William J Bagshaw Mar 05 '18 at 09:14
  • In that case, instead of going to _Paths and Symbols_ use this : (2) In dialog _Properties_, select `C/C++ General > Preprocessor Include etc. > Entries > Languages = C++ > Setting Entries = CDT User Setting` (3) Click Add, select _Include file_ and give the path of the header file. – majji Mar 08 '18 at 14:29