I'm making a project for the ATTiny10 (or smaller). For this project I thought I'd like to use gcc as essentially a "dumb" assembler, but I'm having trouble including the I/O register definitions. I'm using Ubuntu (well, Kubuntu to be exact). The first step was to install gcc-avr.
sudo apt-get install gcc-avr
However, whenever I try to access any I/O register, I get an undefined reference to that label, despite including io.h like so:
I assembled the code using the following command:
avr-gcc -nostdlib -mmcu=attiny10 -DF_CPU=1000000 -g test.s -o test.elf
After a lot of research I have actually found the answer while writing the question. There are two things I figured out I needed to do.
1) The first thing I figured out was that the relevant header files are not actually included in gcc-avr. You actually need to install the avr-libc package as well:
sudo apt-get install avr-libc
This would put the relevant files in /usr/lib/avr/include/avr/
2) This still did not make the include work properly. This, I found out to be due to a quirk documented here. Namely, that C style preprocessor commands would only be parsed in assembly language files by default if the file extension is an upper-case S but not if it's a lower-case s. This would cause the include to silently be completely ignored, as it appeared to just be a comment as far as the assembler is concerned.
Note that the invokation of the C preprocessor will be automatic when the filename provided for the assembler file ends in
.S (the capital letter "s"). This would even apply to operating systems that use case-insensitive filesystems since the actual decision is made based on the case of the filename suffix given on the command-line, not based on the actual filename from the file system.
As an alternative to using
.S, the suffix
.sx is recognized for this purpose (starting with GCC 4.3.0). This is primarily meant to be compatible with other compiler environments that have been providing this variant before in order to cope with operating systems where filenames are case-insensitive (and, with some versions of
makethat could not distinguish between
.S on such systems).
Alternatively, the language can explicitly be specified using the
Hopefully this can help someone in a similar situation.