arduino gcc undefined reference to when size growth [SOLVED]

Hi,
I'm writing an application with arduino uno, this application mix standard "c" code with assembly code.
I've this simple piece of code (that work very nice):

volatile byte n0 = 10;
volatile byte n1 = 20;
 
void setup() {
  Serial.begin(9600);
  Serial.println("-- Before --");
  Serial.print("n0 = "); Serial.println(n0);
  Serial.print("n1 = "); Serial.println(n1);
  test();
  Serial.println("-- After --");
  Serial.print("n0 = "); Serial.println(n0);
  Serial.print("n1 = "); Serial.println(n1);
}
 
void loop(void) { }

void test(){
  asm (
    "lds r24, (n0) \n"
    "lds r26, (n1) \n"
    "sts (n1), r24 \n" //exchange registers
    "sts (n0), r26 \n"
    : : : "r24", "r26" //clobber.
  );  
}

If I copy test function and "volatile byte n0 = 10; volatile byte n1 = 20;" rows into the real project (that contains many rows of C code) I obtain this error:

undefined reference to `n0'

So I've tried to comment out some pieces of the ("large") C code to look for some "conflict".
Doing this, at some point, the error disappear but it seem that the problem isn't a specific conflict but the size of the C code, in fact it seem do not depend about what lines of code I comment out but about how many lines I comment out.

So my question is, anybody know cause and/or solution about this problem?

Ps: if you like, I can paste whole lines of code.

Thanks for your help.

Please post your complete program that causes the error

On a windows system, you can find the sketch that is actually compiled in appdata.

C:\Users\your username\AppData\Local\Temp\arduino_build_828578\sketch.

The file is yoursketch.ino.cpp

The actual directory (in my example arduino_build_828578) can be found when you enable verbose output during compile in file->preferences.

Inspect that sketch for odd things.

You might need to add a function prototype for your function but without full code it's difficult to say.

Thank you for your replay.
I've a problem, the code is too big => "The message exceeds the maximum allowed length (9000 characters)."
But I cannot reduce it because the problem is connected to the code size :frowning:

So ... here you can download the sources.

https://drive.google.com/open?id=10bDbR0zb5QZHdTLx8PFtF3eDc4kPNmvG

Thanks.

Did you move a variable or function declaration out of a .cpp (or .ino) file into a .c file? If you want to reference the function or variable from a .cpp (or .ino) file you should tell the C++ compiler what you have done.

extern "C"
{
volatile byte n0;
volatile byte n1;
}

sterretje:
On a windows system, you can find ...

Hi, I'm working with linux (Ubu18).

johnwasser:
Did you move a variable or function declaration out of a .cpp (or .ino) file into a .c file? If you want to reference the function or variable from a .cpp (or .ino) file you should tell the C++ compiler what you have done.

extern "C"

{
volatile byte n0;
volatile byte n1;
}

Hi, no the variables and the function are declared into ".ino" file.

I've a problem, the code is too big

Then attach it to a post

Compiles fine for me, both for MEGA and UNO.

I got rid of a bunch of warning messages by adding ‘const’ here in decVal.cpp:

String decVal2StrWP(decVal_t val, bool signEnabeld, int len, char um, const char *umArray, int umArray_orig) {

and here in decVal.h:

String decVal2StrWP(decVal_t val, bool signEnabeld, int len, char um, const char *umArray, int umArray_orig);

After that, the only warnings are:

/Users/john/Downloads/gen_imp/gen_imp.ino: In function 'int get_key(unsigned int)':
/Users/john/Downloads/gen_imp/gen_imp.ino:649:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (input < adc_key_val[k]) {
         ~~~~~~^~~~~~~~~~~~~~~~
/Users/john/Downloads/gen_imp/gen_imp.ino: In function 'void menuMainKeys(int)':
/Users/john/Downloads/gen_imp/gen_imp.ino:477:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
       if (!outOnFlag_a) {
       ^~
/Users/john/Downloads/gen_imp/gen_imp.ino:480:5: note: here
     default:
     ^~~~~~~
sketch/decVal.cpp: In function 'String decVal2Str(decVal_t, bool, int, char)':
sketch/decVal.cpp:191:13: warning: unused variable '_e' [-Wunused-variable]
   const int _e = val.e+24;                            LOG_DBG2("_e=" + String(_e));
             ^~
Sketch uses 12422 bytes (4%) of program storage space. Maximum is 253952 bytes.
Global variables use 542 bytes (6%) of dynamic memory, leaving 7650 bytes for local variables. Maximum is 8192 bytes.

I’m using Arduino 1.8.10 on Mac OS X 10.14.6

johnwasser:
I'm using Arduino 1.8.10 on Mac OS X 10.14.6

Hi, I'm using Arduino 1.8.6 on linux (Ubu18), now I'm going to download 1.8.10.

But with Arduino 1.8.6 I obtain:

/tmp/ccSuCks7.ltrans0.ltrans.o: In function generateImpulsesInAnInfiniteLoop': Multiple libraries were found for "LiquidCrystal.h" Used: /home/franco/Arduino/libraries/LiquidCrystal Not used: /home/franco/Arduino/libraries/NewliquidCrystal Not used: /home/franco/Applications/arduino-nightly-linux64/arduino-nightly/libraries/LiquidCrystal /home/franco/Arduino/Ardunino.prjs/Trash/Questions2Cummunity/gen_imp_wih_problems/gen_imp_wih_problems.ino:215: undefined reference to n0'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Uno.

frado:
Hi, I'm using Arduino 1.8.6 on linux (Ubu18), now I'm going to download 1.8.10.

But with Arduino 1.8.6 I obtain:

/tmp/ccSuCks7.ltrans0.ltrans.o: In function generateImpulsesInAnInfiniteLoop': Multiple libraries were found for "LiquidCrystal.h" Used: /home/franco/Arduino/libraries/LiquidCrystal Not used: /home/franco/Arduino/libraries/NewliquidCrystal Not used: /home/franco/Applications/arduino-nightly-linux64/arduino-nightly/libraries/LiquidCrystal /home/franco/Arduino/Ardunino.prjs/Trash/Questions2Cummunity/gen_imp_wih_problems/gen_imp_wih_problems.ino:215: undefined reference to n0'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Uno.

:expressionless:
The problem was the version! After the update it compiles to me also!

Thanks

...

Yes I Know, I Had to update software before but ... if the software works why to change it? :slight_smile:

Many thanks to everyone :slight_smile: