Eclipse CDT C/ c++:包含来自另一个项目的头文件

时间:2023-01-24 19:08:37

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:

我在Eclipse CDT main和shared中有两个c++项目。在shared中,我有一个名为calc.h的头文件。我想用这个标题为主,所以我做了如下:

  • added #include "calc.h to the relevant files in main
  • 添加#include“calc.h”到主相关文件中
  • In main's properties -> Project references i checked of shared
  • 在main的属性中->项目引用我检查了共享。

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.

我希望这能起作用,但我有一个致命的错误:calc.h:编译时没有这样的文件或目录,所以项目引用不管用。

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.

我可以通过在main的属性中手动添加共享的源文件夹来实现它——>C/ c++ Build->设置->GCC c++编译器->包括,但是我有一种不好的感觉,这将在更大的项目上变得麻烦,更复杂的依赖关系。因此,我希望Eclipse能够通过项目引用来处理这个问题。

Am I missing something or is manually the only way?

是我漏掉了什么,还是只有手动操作?

1 个解决方案

#1


11  

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 :

我在大型项目中使用Eclipse CDT,但不使用Eclipse编译器设置。有一些绘图软件可以使用CDT编译器设置:

  • 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.
  • 如果您希望在没有eclipse(当您部署应用程序时)的平台上编译项目,这并不简单。

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

我使用CMake管理我的eclipse项目。当我开始一个新项目时,我会做以下步骤:

  • 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
  • 使用您最喜欢的文本编辑器(vim, emacs, text edit, kate…)创建CMakeLists。txt您的项目。您不必创建一个exaustive CMakeLists,只需创建四个您的第一个文件的小型CMakeLists
  • Then ask cmake to generate the eclipse project thanks to : cmake -G "Eclipse CDT4 - Unix Makefiles"
  • 然后请cmake生成eclipse项目,感谢:cmake - g“eclipse CDT4 - Unix makefile”
  • 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.
  • 打开eclipse,点击File->导入,选择“General/Existing project into workspace”,然后选择第一步创建的文件夹,您的项目就可以在eclipse中使用了。

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

CMake是用于管理项目的编译器配置工具……如果你不知道,我鼓励你去发现它。

Cheers !

干杯!

#1


11  

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 :

我在大型项目中使用Eclipse CDT,但不使用Eclipse编译器设置。有一些绘图软件可以使用CDT编译器设置:

  • 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.
  • 如果您希望在没有eclipse(当您部署应用程序时)的平台上编译项目,这并不简单。

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

我使用CMake管理我的eclipse项目。当我开始一个新项目时,我会做以下步骤:

  • 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
  • 使用您最喜欢的文本编辑器(vim, emacs, text edit, kate…)创建CMakeLists。txt您的项目。您不必创建一个exaustive CMakeLists,只需创建四个您的第一个文件的小型CMakeLists
  • Then ask cmake to generate the eclipse project thanks to : cmake -G "Eclipse CDT4 - Unix Makefiles"
  • 然后请cmake生成eclipse项目,感谢:cmake - g“eclipse CDT4 - Unix makefile”
  • 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.
  • 打开eclipse,点击File->导入,选择“General/Existing project into workspace”,然后选择第一步创建的文件夹,您的项目就可以在eclipse中使用了。

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

CMake是用于管理项目的编译器配置工具……如果你不知道,我鼓励你去发现它。

Cheers !

干杯!