Eclipse CDT 中的项目依赖

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7728878/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 17:09:05  来源:igfitidea点击:

Project dependency in Eclipse CDT

c++eclipse

提问by MarkP

I'm using eclipse for the first time. I'm a seasoned VisualStudio user, so I'm trying to find similar functionality in eclipse. I have two projects, A and B. Project A spits out libA.a when it's done compiling. Project B links against libA.a. Here is my problem.

我是第一次使用 eclipse。我是一个经验丰富的 VisualStudio 用户,所以我试图在 eclipse 中找到类似的功能。我有两个项目,A 和 B。项目 A 在编译完成后会吐出 libA.a。项目 B 链接到 libA.a. 这是我的问题。

  1. I compile project A then project B, everything is fine.
  2. I make a code change to project A that requires a build of project A.
  3. I try to build project B, but it states that no changes have been detected.
  1. 我编译项目A然后项目B,一切都很好。
  2. 我对需要构建项目 A 的项目 A 进行了代码更改。
  3. 我尝试构建项目 B,但它指出未检测到任何更改。

How do I make project B aware of the output of project A?? Currently I'm having to do a clean build of project B for it to re-link against libA.a.

我如何让项目 B 知道项目 A 的输出?目前,我必须对项目 B 进行干净的构建,才能重新链接 libA.a。

Thanks.

谢谢。

EDIT: In my ProjectB->Path and Symbols->References tab, I have project A checked. This doesn't relink after project A is rebuilt.

编辑:在我的 ProjectB->Path 和 Symbols->References 选项卡中,我选中了项目 A。这在项目 A 重建后不会重新链接。

采纳答案by KeithSmith

One can work around this problem by using the 'touch' command.

可以通过使用“touch”命令来解决这个问题。

In Eclipse, as part of C/C++ Build/Settings is the tab 'Build Steps'. In the pre-build steps command line, enter 'touch filename'.

在 Eclipse 中,作为 C/C++ 构建/设置的一部分是“构建步骤”选项卡。在预构建步骤命令行中,输入“touch filename”。

'filename' is any file in your application. This could be the file with main(). This could be a special file just for this workaround, touchdummy.c, which can be a tiny file, which compiles quickly.

'filename' 是应用程序中的任何文件。这可能是带有 main() 的文件。这可能是一个专门用于此解决方法的特殊文件 touchdummy.c,它可以是一个可以快速编译的小文件。

When the application builds, even if you didn't change any sources, the 'touch' command causes make to rebuild the application. If the library was rebuilt, then the application gets rebuilt with the new library.

当应用程序构建时,即使您没有更改任何源,“touch”命令也会导致 make 重建应用程序。如果重建了库,则应用程序将使用新库重建。

One can read about how 'touch' affects the date/time of the file here. http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html

可以在此处阅读“触摸”如何影响文件的日期/时间。 http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html

Edit: The exact command in Eclipse would be touch ${ProjDirPath}/src/main.c

编辑:Eclipse 中的确切命令是 touch ${ProjDirPath}/src/main.c

Edit: This command should work, but it appears that if the 'main' project did not change, the pre-build step is not executed. Also the 'touch' command causes eclipse to prompt to reload the file it touched. A large annoyance.

编辑:此命令应该可以工作,但似乎如果“主”项目没有更改,则不会执行预构建步骤。此外,'touch' 命令会导致 eclipse 提示重新加载它所接触的文件。一大烦恼。

回答by Mamatha

Try the below settings:

尝试以下设置:

  1. Go to properties of Main ProjectC/C++ GeneralPaths and SymbolsReferences
  2. Tick all the dependencies.
  1. 转到Main Project 的属性 → C/C++ GeneralPaths and SymbolsReferences
  2. 勾选所有依赖项。

回答by nos

You go into Project Properties of Project B, select Project References and make it reference (depend) on Project A.

您进入项目 B 的项目属性,选择项目引用并使其引用(依赖)于项目 A。

Edit, appears to be a known bug

编辑,似乎是一个已知的错误

回答by COD3BOY

Eclipse projects depend on each other by virtue of the checkbox in the project's properties (dependent projects?) which is how Eclipse decides which to build. You can set this yourself, but it's usually set when you change your Java build path.

Eclipse 项目依赖于项目属性(依赖项目?)中的复选框,Eclipse 决定构建哪个项目。您可以自己设置,但通常在您更改 Java 构建路径时设置。

回答by Michael Tomlinson

By default at least with QNX C++ projects, it WILL NOT check for changes in other projects. Right click on the project, and expand "check dependencies on/off"->"check user headers only" It seems to work, roughly... It appears to do a makedepends on the code, and adds *.d files to the output folder which are simply depends file that list the header files. Note: these do not appear to get regenerated, and get out of date - I do not know how to regenerate them.

默认情况下,至少对于 QNX C++ 项目,它不会检查其他项目中的更改。在项目上右击,展开“check dependencies on/off”->“check user headers only” 好像能用,大致... 好像是根据代码做了一个makedepends,然后把*.d文件加到输出文件夹只是列出头文件的依赖文件。注意:这些似乎不会再生,也不会过时 - 我不知道如何再生它们。