简体   繁体   English

Eclipse CDT 中的项目依赖关系

[英]Project dependency in Eclipse CDT

I'm using eclipse for the first time.我是第一次使用eclipse。 I'm a seasoned VisualStudio user, so I'm trying to find similar functionality in eclipse.我是一位经验丰富的 VisualStudio 用户,所以我试图在 eclipse 中找到类似的功能。 I have two projects, A and B. Project A spits out libA.a when it's done compiling.我有两个项目,A 和 B。项目 A 在编译完成后会吐出 libA.a。 Project B links against libA.a.项目 B 链接到 libA.a。 Here is my problem.这是我的问题。

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

How do I make project B aware of the output of project A??如何让项目 B 知道项目 A 的输出? Currently I'm having to do a clean build of project B for it to re-link against libA.a.目前,我必须对项目 B 进行干净构建,才能重新链接到 libA.a。

Thanks.谢谢。

EDIT: In my ProjectB->Path and Symbols->References tab, I have project A checked.编辑:在我的 ProjectB->Path and Symbols->References 选项卡中,我检查了项目 A。 This doesn't relink after project A is rebuilt.重建项目 A 后,这不会重新链接。

Try the below settings:尝试以下设置:

  1. Go to properties of Main ProjectC/C++ GeneralPaths and SymbolsReferences转到主项目的属性 → C/C++ 常规路径和符号参考
  2. Tick all the dependencies.勾选所有依赖项。

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编辑,似乎是一个已知的错误

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'.在 Eclipse 中,作为 C/C++ 构建/设置的一部分,是选项卡“构建步骤”。 In the pre-build steps command line, enter touch filename .在预构建步骤命令行中,输入touch filename

filename is any file in your application. filename是应用程序中的任何文件。 This could be the file with main() .这可能是带有main()的文件。 This could be a special file just for this workaround, touchdummy.c , which can be a tiny file, which compiles quickly.这可能是一个专门用于此解决方法的特殊文件touchdummy.c ,它可以是一个可以快速编译的小文件。

When the application builds, even if you didn't change any sources, the touch command causes make to rebuild the application.当应用程序构建时,即使您没有更改任何源, touch命令也会导致 make 重新构建应用程序。 If the library was rebuilt, then the application gets rebuilt with the new library.如果库已重建,则应用程序将使用新库重建。

One can read about how touch affects the date/time of the file here.可以在此处阅读有关touch如何影响文件的日期/时间的信息。 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. touch命令也会导致 eclipse 提示重新加载它接触的文件。 A large annoyance.一个很大的烦恼。

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. Eclipse 项目通过项目属性(依赖项目?)中的复选框相互依赖,这是 Eclipse 决定构建哪个项目的方式。 You can set this yourself, but it's usually set when you change your Java build path.您可以自行设置,但通常在您更改 Java 构建路径时设置。

By default at least with QNX C++ projects, it WILL NOT check for changes in other projects.默认情况下,至少对于 QNX C++ 项目,它不会检查其他项目中的更改。 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.右键单击该项目,然后展开“检查依赖项开/关”->“仅检查用户标头”它似乎工作,大致......它似乎做了一个makedepends代码,并将* .d文件添加到输出文件夹,它只是列出头文件的依赖文件。 Note: these do not appear to get regenerated, and get out of date - I do not know how to regenerate them.注意:这些似乎没有被重新生成,并且已经过时 - 我不知道如何重新生成它们。

For Project A (library):对于项目 A(库):

Properties>C/C++ Build>Settings>Build Steps>Post-build steps> touch -m ${ProjDirPath}/source/build/build_updated.cpp属性>C/C++ 构建>设置>构建步骤>构建后步骤> touch -m ${ProjDirPath}/source/build/build_updated.cpp

You should create folder "source/build" firstly and don't add in that folder any other files.您应该首先创建文件夹“source/build”,并且不要在该文件夹中添加任何其他文件。

For Project B:对于项目 B:

Properties>Project References> check Project A属性>项目参考>检查项目A

Properties>С/С++ General>Paths and Symbols>Source Location>Link Folder>Link to folder in the file system> find and pick "source/build" folder which you created for project A before.属性>С/С++常规>路径和符号>源位置>链接文件夹>链接到文件系统中的文件夹>找到并选择您之前为项目A创建的“源/构建”文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM