[chbot] AVR linker issue (?)

Andrew Dachs dachsa492 at gmail.com
Sat Jul 17 23:14:41 BST 2021


A dependency issue maybe. Did it definitely recompile font.c? 
Andy

Sent from my iPhone

> On 18/07/2021, at 9:02 AM, Mark Atherton <markaren1 at xtra.co.nz> wrote:
> 
> I need another pair of eyes to look at this issue as am obviously doing something daft. This is part of a larger problem; minimal code to show issue is below.
> 
> All I am trying to do is move a table into a separate module, but the linker is giving me a hard time.
> 
> Remove 'const' in the external module and everything works fine.
> 
> Thoughts please !
> 
> -Mark
> 
> 
> -------------
> 
> mkdir -p .build
> avr-g++ -c -g -Os -Wall -w -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L font.c -o .build/font.o
> avr-g++ -c -g -Os -Wall -w -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L main.c -o .build/main.o
> avr-gcc .build/font.o .build/main.o -o .build/hw.elf -Os -Wl,--gc-sections -mmcu=atmega328p -lm
> 
> .build/main.o: In function `main':
> C:\Temp\linker_test/main.c:18: undefined reference to `ext_font'
> collect2.exe: error: ld returned 1 exit status
> make: *** [.build/hw.elf] Error 1
> 
> ------------- font.c
> 
> #include <avr\pgmspace.h>
> 
> const unsigned char ext_font[] =        // links OK with const removed
> {
>  0x00, 0x00, 0x00, 0x00, 0x00
> };
> 
> ------------- font.h
> 
> #ifndef    _FONT_H_
> #define _FONT_H_
> 
> extern const unsigned char ext_font[5]; // links OK with const removed
> 
> #endif
> 
> ------------- main.c
> 
> #include <avr\io.h>
> #include <avr\pgmspace.h>
> #include <ctype.h>
> #include "font.h"
> 
> const unsigned char local_font[] = // const has no effect on linker !!
> {
>  0x00, 0x00, 0x00, 0x00, 0x00
> };
> 
> int main(void)
> {
>  volatile unsigned char val;
>  val = local_font[3];        // links OK
>  val = ext_font[3];        // link Fails
> 
> }
> 
> _______________________________________________
> Chchrobotics mailing list Chchrobotics at lists.ourshack.com
> https://lists.ourshack.com/mailman/listinfo/chchrobotics
> Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> Meetings usually 3rd Monday each month. See http://kiwibots.org for venue, directions and dates.
> When replying, please edit your Subject line to reflect new subjects.



More information about the Chchrobotics mailing list