|
|
|
Re: AVR-GCC Assembly help [message #1746816 is a reply to message #1746765] |
Fri, 04 November 2016 23:42 |
David Vavra Messages: 1426 Registered: October 2012 |
Senior Member |
|
|
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 10:25 |
Tauno Voipio Messages: 742 Registered: August 2014 |
Senior Member |
|
|
Rod Naugler wrote on Fri, 04 November 2016 13:08I'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.
--
Tauno Voipio
[Updated on: Sat, 05 November 2016 10:26] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02878 seconds