SPI.h compile error, error: 'g_ioport_ctrl' was not declared in this scope

The problem is something to do with file structure or includes.
It compiles, if have one header file in library.

My original structure was


The SPI.h include is in MAX7219plus.h
I removed all the TM* files and If I put common_data.h and seven_segment_font_data.h in MAX7219plus.h file , it compiles.
The Wprogram.h in diagram should read Arduino.h.

This only happens on R4 minima , no other board throws an error.