Global variables in library projects


I have a working application project that  I'm trying to split into an application and 2 libraries. But after the split the code in the libraries does not behave the same as when it was just a single application. What I have noticed is that initialized global variables are placed in different linker sections. When linked as an single application they are placed in RAM , while linked as an library they are placed in the ROM

Is there any problem using initialized global variables in libraries?

They need to be assignable from the code, not const as when placed in ROM

I'm using HEW and targeting a 1638F MCU


  • There shouldn't be a difference if your global variables are in a lib or not, they should be placed in "Initialized data area D* Yes" if in C, in C++ in C$Init section which is manually initialized calling _CALL_INIT() right after _INITSCT().

    In case the variables are not written somewhere else beside initialization then they might be optimized as const and placed in RAM.

    Hope it helps...

  • Problem solved!

    The project was missing the linker flag -rom=D=R. I had created an empty project and was not aware of the flag.

    /Jakob Pousard
  • In reply to jakpou:


    I am glad to hear you have resolved your issue and thank you for sharing the solution. Hopefully, this will also be helpful to someone else.

    Mike Clements
    RenesasRulz Moderator