Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Managing Project and Library Dependencies With Eclipse CDT

DZone's Guide to

Managing Project and Library Dependencies With Eclipse CDT

Building libraries to use in Eclipse CDT projects? See how you can link to them efficiently (and update changes) while overcoming a bug.

· IoT Zone ·
Free Resource

For several projects, I’m using library projects: I build a library and then use that library in another project. If I change something in a library, I want to run make both on the referenced libraries and rebuild my application if needed. If you don’t know how to do this, then read on…

Shared Library Projects

Shared Library Projects

(…Actually, it means working around the known Eclipse CDT bug, too….)

Outline

I’m using the MCUXpresso IDE v10.0.2 in this, but basically, it should be the same for any other Eclipse CDT distribution (e.g. Kinetis Design Studio or others).

In this article, I’m going to use three projects:

  • A is a library project producing the library libA.a
  • B is a library project producing the library libB.a
  • C is the application project and uses libA.a and libB.a


Shared Library Projects

Shared Library Projects

Below, we see the projects and output files in Eclipse:

Projects in Eclipse

Projects in Eclipse

When compiling Project C, it shall:

  • Rebuild Project A and/or B if they have changed.
  • If A or B have changed, the project C shall link the new libraries.

Project References

In the project settings, there is the ‘Project References’ section:

Project References

Project References

Referencing another project will check and build the referenced projects. As for above, if I build Project ‘C’, it will go and first build ‘A’, then ‘B’, and finally ‘C’.

The thing is: this only triggers running the make process for the referenced projects. It will *not* trigger a make for the ‘C’ project if one of the referenced projects is changing. I still have to run the build/make for the ‘C’ project.

Linking Libraries

The usual way to link libraries with the application is shown below using the -l and -L linker options:

Linking Libraries

Linking Libraries

Now, one would think that this is all that is needed: With the libraries listed in the linker options, it will relink the application if one of the referenced libraries changes? Actually, this is not the case. It will only build and relink the project if a file of the project itself has changed, but not if a referenced project has changed.

I have found this as a bug in Eclipse CDT managed make. One can see the problem with the managed make file produced by Eclipse CDT:

# Tool invocations
C.axf: $(OBJS) $(USER_OBJS)
 @echo 'Building target: $@'
 @echo 'Invoking: MCU Linker'
 arm-none-eabi-gcc -nostdlib -L../../A/Debug/ -L../../B/Debug/ -Xlinker -Map="C.map" -Xlinker --gc-sections -Xlinker -print-memory-usage -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -T "c_app_Debug.ld" -o "C.axf" $(OBJS) $(USER_OBJS) $(LIBS)
 @echo 'Finished building target: $@'
 @echo ' '
 $(MAKE) --no-print-directory post-build


The rule for C.axf only depends on the project object files, plus any user object files. The target C.axf does *not* depend on the $(LIBS), which I have specified above in the linker options.

See Tutorial: Makefile Projects with Eclipse for a more detailed view about make files and make rules.

Other Objects

The solution (or better workaround) I’m using is to specify the libraries in the $(USER_OBJS) list, which are configured as ‘Other objects’:

Other objects

Other objects

With this, if I build the ‘C’ project and the ‘other objects’ have been changed, it will link them.

Summary

I can use the ‘Project References’ setting in Eclipse CDT to reference other projects. Eclipse will call make for the referenced projects when I build the ‘master’ projects, which is a handy thing for the library projects my application depends on. In order to trigger a re-linking of my master project, if any of the depending projects have been changed, I have to specify the libraries in the ‘Other objects’ settings. Then everything works as I would expect it.

Happy Depending!

Links

Topics:
iot ,eclipse cdt ,library ,dependencies ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}