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