Program no longer compiling

Hi Guys,

I have been playing around with Assembly on the Arduino and al was going great yesterday. Now today when I open my project compilation fails early declaring the function in the '.S' file.

Summary

one.S:5:1: error: expected unqualified-id before '.' token
.global start

My '.ino' file

extern "C" 
{
  void start();
  void forever();
}

void setup()
{
  noInterrupts();
  start();
}

void loop() 
{
  forever();
}

And the '.S' file

#define __SFR_OFFSET 0

#include "avr/io.h"

.global start
.global forever

start:
    SBI DDRB, 2
    RET

forever:
L1:
    LDI R16, 0x00
    SBI PORTB, 2

LOOP1:    
    INC R16
    CPI R16, 0x0A
    BRNE LOOP1
    JMP L2

L2:    
    CBI PORTB, 2
    JMP L1

And the error log

Arduino: 1.8.16 (Windows 10), Board: "Arduino Uno"

P:\Arduino\One\one.S:1:0: warning: "__SFR_OFFSET" redefined

 #define __SFR_OFFSET 0

 

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

                 from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\pgmspace.h:90,

                 from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28,

                 from sketch\one.S.cpp:1:

c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\sfr_defs.h:172:0: note: this is the location of the previous definition

 #    define __SFR_OFFSET 0x20

 

one.S:5:1: error: expected unqualified-id before '.' token

 .global start

 ^

P:\Arduino\One\one.ino: In function 'void setup()':

one:10:3: error: 'start' was not declared in this scope

   start();

   ^~~~~

P:\Arduino\One\one.ino:10:3: note: suggested alternative: 'sqrt'

   start();

   ^~~~~

   sqrt

P:\Arduino\One\one.ino: In function 'void loop()':

one:15:3: error: 'forever' was not declared in this scope

   forever();

   ^~~~~~~

P:\Arduino\One\one.ino:15:3: note: suggested alternative: 'free'

   forever();

   ^~~~~~~

   free

exit status 1

expected unqualified-id before '.' token



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

It's got me stumped as it was compiling all day yesterday without a hitch.

Any advice would be greatly appreciated.

Many thanks in advance!

That's suspicious, something's adding a .cpp suffix.

1 Like

Hi Mark,

A weird thing I just found (that makes it work), is if I make a backup of the '.S' file, delete the original file so it doesn't appear in the editor, then rename the backup to the original filename again, it compiles happily. Any changes I make in the '.S' file (via notepad) take affect also.

So if the file appears in the editor, it won't compile. If it's not in the editor, it will compile.

I can't see any way of closing the '.S' file from the editor without deleting it, using the method mentioned above.

Very strange. I have a sort of workaround, but not really ideal.

This is what the log file looks like using the above method.

I'm not sure how it's building the '.S' file as it says "Using previously compiled file:", but it certainly is making the changes that I'm doing on the assembly file in an external editor.

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\User\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=2341_0043 -ide-version=10816 -build-path C:\Users\User\AppData\Local\Temp\arduino_build_386948 -warnings=none -build-cache C:\Users\User\AppData\Local\Temp\arduino_cache_442155 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose P:\Arduino\VGA\vga.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\User\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=2341_0043 -ide-version=10816 -build-path C:\Users\User\AppData\Local\Temp\arduino_build_386948 -warnings=none -build-cache C:\Users\User\AppData\Local\Temp\arduino_cache_442155 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose P:\Arduino\VGA\vga.ino
Using board 'uno' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Detecting libraries used...
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_386948\\sketch\\vga.ino.cpp" -o nul
Generating function prototypes...
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_386948\\sketch\\vga.ino.cpp" -o "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_386948\\preproc\\ctags_target_for_gcc_minus_e.cpp"
"C:\\Program Files (x86)\\Arduino\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_386948\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_386948\sketch\vga.S.o
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_386948\\sketch\\vga.ino.cpp" -o "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_386948\\sketch\\vga.ino.cpp.o"
Compiling libraries...
Compiling core...
Using precompiled core: C:\Users\User\AppData\Local\Temp\arduino_cache_442155\core\core_arduino_avr_uno_0c812875ac70eb4a9b385d8fb077f54c.a
Linking everything together...
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_386948/vga.ino.elf" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_386948\\sketch\\vga.S.o" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_386948\\sketch\\vga.ino.cpp.o" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_386948/..\\arduino_cache_442155\\core\\core_arduino_avr_uno_0c812875ac70eb4a9b385d8fb077f54c.a" "-LC:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_386948" -lm
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_386948/vga.ino.elf" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_386948/vga.ino.eep"
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-objcopy" -O ihex -R .eeprom "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_386948/vga.ino.elf" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_386948/vga.ino.hex"
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-size" -A "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_386948/vga.ino.elf"
Sketch uses 478 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.