Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » AVR-GCC Assembly help(Trying to compile test.S get /usr/lib/gcc/avr/4.9.2/../../../avr/lib/avr5/crtatmega644a.o:(.init9+0x0): undefined reference to `main')
AVR-GCC Assembly help [message #1746741] Thu, 03 November 2016 20:24 Go to next message
Eclipse UserFriend
Hi all,
As part of a university course we are required to program an Atmel Microcontroller in ASM. I have gotten gavrasm running, but not with eclipse and I've been encouraged to use avr-gcc instead. I've gotten a basic Test.S file compiling but it fails in a later stage with the following error:
/usr/lib/gcc/avr/4.9.2/../../../avr/lib/avr5/crtatmega644a.o:(.init9+0x0): undefined reference to `main'

Can anyone help me understand what's going on?

Thanks!
Re: AVR-GCC Assembly help [message #1746758 is a reply to message #1746741] Fri, 04 November 2016 06:01 Go to previous messageGo to next message
Eclipse UserFriend
The avr-gcc compiler driver is attempting to link your object module with the standard AVR start-up code and C library. The complaint comes from the linker, as it does not find the standard C starting entry main().

You can invoke the assembler using avr-as instead of avr-gcc, but it does not expand pre-processor macros (which your .S file implies).

You can prevent the linking phase by adding the -c switch to the avr-gcc command line.

The linker can be invoked with avr-ld. Depending on your assembly code, you may skip the linking phase, if the code is absolute already.
Re: AVR-GCC Assembly help [message #1746765 is a reply to message #1746758] Fri, 04 November 2016 07:08 Go to previous messageGo to next message
Eclipse UserFriend
I'm not 100% sure of what you've told me as I'm not 100% sure how Eclipse works with ASM files. I have edited the c/c++ build settings, under AVR Assembler settings and added the -c to the avr-gcc command (avr-gcc -c) and I can see it in the command window:

 **** Build of configuration Debug for project avr-asm-test ****

make all 
Building file: ../test.S
Invoking: AVR Assembler
avr-gcc -c -x assembler-with-cpp -g2 -gstabs -mmcu=atmega644a -DF_CPU=14745600UL -MMD -MP -MF"test.d" -MT"test.d" -c -o "test.o" "../test.S"
Finished building: ../test.S
 
Building target: avr-asm-test.elf
Invoking: AVR C++ Linker
avr-g++ -Wl,-Map,avr-asm-test.map,--cref -mrelax -Wl,--gc-sections -mmcu=atmega644a -o "avr-asm-test.elf"  ./test.o   
/usr/lib/gcc/avr/4.9.2/../../../avr/lib/avr5/crtatmega644a.o:(.init9+0x0): undefined reference to `main'
makefile:59: recipe for target 'avr-asm-test.elf' failed
collect2: error: ld returned 1 exit status
make: *** [avr-asm-test.elf] Error 1

**** Build Finished ****

Re: AVR-GCC Assembly help [message #1746816 is a reply to message #1746765] Fri, 04 November 2016 19:42 Go to previous messageGo to next message
Eclipse UserFriend
You need to understand how a C program is run. Eclipse is expecting objects will conform to the C layout model.

Normally, the layout for a C program is
- startup code
- main + other functions
- exit code

In C, the startup and exit code is in the standard C libraries.
When the program is executed the entry point is in the startup code.
During startup execution it will call main.
When the program is done, it returns to the exit code which ends up returning to the OS.

Modules are normally created in object format by compiling and assembling. These are then linked together along with other objects from libraries to form an executable.

The error you are seeing is caused by GCC adding the startup code which wants a main function.


Your program can take one of three forms:
1) it can startup the way an OS would start (that is, it is the OS)
2) It can be started as a program by the OS which eventually tells the OS when it is done
3) if can use the C layout model

I don't know which you are trying to make plus I'm not familiar with the device you are building for.

If your program is type (2) above, you may be able to avoid dragging in the C library by using the GCC loader options -nostartfiles, -nodefaultlibs, and -nostdlib during the linking phase.

GCC ld options: https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html

When using GCC to execute ld you need to use -Wl,<option> for some options.
GCC options summary: https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html

You may also need to specify the entry point. The following link shows how but I can't readily find the option so I'm not sure it's still available.
http://stackoverflow.com/a/7494273/3312726

If your program is type (1) you may be able to bypass the linking phase but to do this you will need to change the tool chain to not call the linker. Another way is execute the assembler in a command console and only use Eclipse as an editor.

If you want to make a type (3), then add a main function and use it as your entry point.






Re: AVR-GCC Assembly help [message #1746832 is a reply to message #1746765] Sat, 05 November 2016 06:25 Go to previous message
Eclipse UserFriend
Rod Naugler wrote on Fri, 04 November 2016 13:08
I'm not 100% sure
 **** Build of configuration Debug for project avr-asm-test ****

make all 
Building file: ../test.S
Invoking: AVR Assembler
avr-gcc -c -x assembler-with-cpp -g2 -gstabs -mmcu=atmega644a -DF_CPU=14745600UL -MMD -MP -MF"test.d" -MT"test.d" -c -o "test.o" "../test.S"
Finished building: ../test.S
 
Building target: avr-asm-test.elf
Invoking: AVR C++ Linker
avr-g++ -Wl,-Map,avr-asm-test.map,--cref -mrelax -Wl,--gc-sections -mmcu=atmega644a -o "avr-asm-test.elf"  ./test.o   
/usr/lib/gcc/avr/4.9.2/../../../avr/lib/avr5/crtatmega644a.o:(.init9+0x0): undefined reference to `main'
makefile:59: recipe for target 'avr-asm-test.elf' failed
collect2: error: ld returned 1 exit status
make: *** [avr-asm-test.elf] Error 1

**** Build Finished ****



It seems to me that you're using the internal Makefile builder, which has contradictory instructions for configuration: The compilation is made using simple C compiler (avr-gcc), but the linking is done with C++ linkage setup.

Try from console, in the object file directory:
avr-ld -Map=avr-asm-test.map -mcu=atmega644a -o avr-asm-test.elf test.o

Your assembly-only project is ill-suited for the automatic Makefile generation. IMHO, you should create a Makefile project for it and create the make file by hand.
There are good instructions in the GNU Make manual, and the Net contains plenty of instructions for using the linker.

Also, this project may need a linker script tailored to the processor at hand.

[Updated on: Sat, 05 November 2016 06:26] by Moderator

Previous Topic:build is very slow
Next Topic:Neon.1: Remote Debug problem
Goto Forum:
  


Current Time: Tue Jul 08 16:53:18 EDT 2025

Powered by FUDForum. Page generated in 0.05113 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top