Topic : Linker configuration

Forum : ARM

Original Post
Post Information Post
August 23, 2012 - 5:20pm
Guest

I am trying to get to grips with some code written elsewhere in our company. Ride is new to me.

There is a snippet of code
_EXTERNAL_NVRAM_ stNVRAMDATA gstNVRAM;
which with
#define _EXTERNAL_NVRAM_ extern
parses as
extern stNVRAMDATA gstNVRAM;

Looking in the *.ld files, I can see no reference to gstNVRAM, so what defines where gstNVRAM is placed and how do I view/edit the same?

Thanks

Replies
Post Information Post
+1
0
-1
August 23, 2012 - 6:01pm
Raisonance Support Team

Hello,

This is only the _declaration_. It also has to be _defined_ somewhere.
It's usualy defined in a C or assembler file.
It could also be in the ld file but that's not the normal way to proceed, unless thie variable needs a "special treatment" during link.

If the application links successfully, then I guess one of your C files directly defines gstNVRAM without "extern". Or maybe it redefines _EXTERNAL_NVRAM_ differently, and then both the definition and the declaration are in the same place, but _EXTERNAL_NVRAM_ means different things depending on which C file includes the h file.
Or maybe the symbol is never referenced. I.e. it is not used, so it's not defined but it's not a problem.
In this case I suggest you search the symbol in the map file and you should see where it is defined and what address it is placed at by the linker.

If the application does not link, you have to define it, either in the ld file or in a C (or assembler) file.

Note that this is true for all C development. It is not secific to Ride or ARM or GCC: all compile chains have an equivalent to ld files, and the rest is standard C.

I recommend you make sure you are at ease with things like "extern", "declaration", "definition", "#define", etc. (which are all different things) before working in C...:
http://en.wikipedia.org/wiki/External_variable
http://en.wikipedia.org/wiki/C_preprocessor

Best regards,

Vincent