For several projects I’m using library projects: I build a library and then use that library in the other 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… 🙂
(… actually it means workign around known Eclipse CDT bug too….)
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
Below it shows the projects and output files in Eclipse:
When compiling the project C, it shall:
- rebuild the project A and/or B if they have changed
- if A or B have changed, the project C shall link the new libraries
In the project settings, there are the ‘Project References’:
Referencing another project will check and build the referenced projects. As for above, if I build the project ‘C’, it will go and build first ‘A’, then ‘B’ and finally ‘C’.
The think 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.
The usual way to link libraries with the application is shown below, using the -l and -L linker options:
Now one would think that this is all what is needed: with the libraries listed in the linker options, it will relink the application if one of the referenced libraries? 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.
The solution (or better workaround) I’m using is to specify the libraries in the $(USER_OBJS) list which are configured as ‘Other objects’:
With this: if I build the ‘C’ project and the ‘other objects’ have been changed, it will link them.
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 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 🙂