Error - undefined reference to `main'

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've done a fair amount of searching, and this error seems to mean that the compiler can't find the main() function. I just can't seem to figure out why. I have been following a tutorial (http://interactive-matter.eu/how-to/developing-software-for-the-atmel-avr-with-avr-eclipse-avr-gcc-avrdude/) on setting up Eclipse to program AVR. I added the simpleist main.c that I could think of:

 

int main(void) {
 while(1);
}

 

The console output is: 

11:25:57 **** Incremental Build of configuration Release for project Test ****
make all
Building target: Test.elf
Invoking: AVR C Linker
avr-gcc -Wl,-Map,Test.map -mmcu=atmega32 -o "Test.elf"  ./main.o   
c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr5/crtm32.o:(.init9+0x0): undefined reference to `main'
make: *** [Test.elf] Error 1

11:25:57 Build Finished (took 170ms)

 

Errors:

make: *** [Test.elf] Error 1

undefined reference to `main'

 

Eclipse seems to be calling avr-gcc. I'm pretty green when it comes to programming AVRs. I don't really know where to look next. Any ideas would be greatly appreciated.

 

Terry

This topic has a solution.
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Show the command as main.c is compiled to main.o

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm not too sure what you mean. I've checked that main.o has data in it but I don't understand the GCC tool chain. I've included the text of the makefile. I'm hoping that includes the commands your asking for.

 

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

-include ../makefile.init

RM := rm -rf

# All of the sources participating in the build are defined here
-include sources.mk
-include subdir.mk
-include objects.mk

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(ASM_DEPS)),)
-include $(ASM_DEPS)
endif
ifneq ($(strip $(S_DEPS)),)
-include $(S_DEPS)
endif
ifneq ($(strip $(S_UPPER_DEPS)),)
-include $(S_UPPER_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif

-include ../makefile.defs

# Add inputs and outputs from these tool invocations to the build variables
LSS += \
Test.lss \

SIZEDUMMY += \
sizedummy \

# All Target
all: Test.elf secondary-outputs

# Tool invocations
Test.elf: $(OBJS) $(USER_OBJS)
    @echo 'Building target: $@'
    @echo 'Invoking: AVR C Linker'
    avr-gcc -Wl,-Map,Test.map -mmcu=atmega32 -o "Test.elf" $(OBJS) $(USER_OBJS) $(LIBS)
    @echo 'Finished building target: $@'
    @echo ' '

Test.lss: Test.elf
    @echo 'Invoking: AVR Create Extended Listing'
    -avr-objdump -h -S Test.elf  >"Test.lss"
    @echo 'Finished building: $@'
    @echo ' '

sizedummy: Test.elf
    @echo 'Invoking: Print Size'
    -avr-size --format=avr --mcu=atmega32 Test.elf
    @echo 'Finished building: $@'
    @echo ' '

# Other Targets
clean:
    -$(RM) $(ELFS)$(OBJS)$(ASM_DEPS)$(S_DEPS)$(SIZEDUMMY)$(S_UPPER_DEPS)$(LSS)$(C_DEPS) Test.elf
    -@echo ' '

secondary-outputs: $(LSS) $(SIZEDUMMY)

.PHONY: all clean dependents
.SECONDARY:

-include ../makefile.targets

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, I figured it out. I feel a bit stupid. I started trying to figure out what the make file is actually doing. Suddenly it occurred to me that the compiler isn't really a part of Eclipse. All those little tweaks I made trying to get the project to build didn't do anything since I never actually saved them to disk.

 

Sometimes I think monitors should come with a robotic arm, so the person on the other end could give me a virtual smack in the side of the head.

 

Thank you for your help

Terry