Eclipse CDT C/C++: Include a header file from anot

2019-03-11 01:42发布

I have two c++ projects in Eclipse CDT main and shared. In shared i have a header called calc.h. I want to use this header in main, so i did the following:

  • added #include "calc.h to the relevant files in main
  • In main's properties -> Project references i checked of shared

I hoped this would work, but I get a fatal error: calc.h: No such file or directory when compiling, so the project reference somehow doesn't work.

I can get it to work by manually adding shared's source folder in main's properties->C/C++ Build->Setting->GCC C++Compiler->Includes, but my i have a bad feeling that this will become cumbersome on larger projects more complex dependencies. I'll therefore hoped that Eclipse could handle this via project references.

Am I missing something or is manually the only way?

1条回答
成全新的幸福
2楼-- · 2019-03-11 02:14

You are right, this his the way to do it !

I use Eclipse CDT on large project, but I don't use the eclipse compilers settings. There are some drawbakcs to use the CDT compilers settings :

  • As you said, on large project, this is cumbersome.
  • If you want to compile you project on a platform which doesn't have eclipse (when you deploy you application), that is not straightforward.

I use CMake to manage my eclipse projects. When I start a new project, I do the following steps :

  • In a terminal : Create a folder for your new project
  • With your favorite text editor (vim, emacs, Text edit, kate ...) create the CMakeLists.txt of your project. You don't have to create an exaustive CMakeLists, just a small CMakeLists four your first files
  • Then ask cmake to generate the eclipse project thanks to : cmake -G "Eclipse CDT4 - Unix Makefiles"
  • Open eclipse, and click on File->Import, and choose "General/Existing project into workspace", then you can choose the folder created in the first step, and your project is ready to use in eclipse.

CMake is THE compiler configuration tool to manage projects... If you don't know it I encourage you to discover it.

Cheers !

查看更多
登录 后发表回答