tags:

views:

168

answers:

1

For an embedded system I need to place a few data structures at fixed addresses, so that a separate control CPU can access them at a known location. I'm using linker scripts for the embedded target to accomplish this, plus #defines of those same addresses for the control CPU.

It bothers me that these address constants are therefore defined in two places, the linker script and a header file. I'd like to have just one. The best solution I've come up with so far is to have the Makefile run cpp on the linker script, allowing it to #include the same header.

Is there a better way to accomplish this? Is there some little-known option to ld or a naming convention for the linker script which will automatically run it through cpp?

+2  A: 

This isn't quite the solution you are looking for but one option is to utilize the build system to configure these values. Create a config.h.in and a target.ld.in which acts as templates and have the build system produce a config.h with the correct define and a target.ld with the correct address for the target you are building.

We use CMake for our embedded systems and it supports this kind of thing. GNU autoconf does too but I never really liked it personally.

David Holm
This is what I ended up doing. I run "cpp -P" on an input script to produce the final linker script.
DGentry