Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: PLS HELP - undefined reference to 'main'
PostPosted: Tue May 29, 2012 12:29 am 
Offline

Joined: Tue May 15, 2012 11:11 pm
Posts: 9
I'm using Atmel Studio 6 with SAM3SEK-2.

I changed main.c to main.cpp because I really would like to use C++. I also change "int main(void)" to "extern "C" static int main(void)".

When I build, I am getting "undefined reference to 'main'" in startup_sam3sd8.c.

That file is C code that calls main(), and has, at the top of the file, the definition - int main(void).

I did objdump -t for the main.o file, and the line for the main method is --
000002a4 g F .text 00000242 main

Doing the same command for the startup_sam3sd8.o file gives --
00000000 *UND* 00000000 main

Why are these not resolving??
To be honest, I do not know what the columns in this dump output mean. What do I need to do in order to use C++ in Studio 6 with the ASF code??


Top
 Profile  
 
 Post subject: Re: PLS HELP - undefined reference to 'main'
PostPosted: Tue May 29, 2012 9:38 pm 
Offline

Joined: Tue May 29, 2012 9:21 pm
Posts: 3
I used c++ without issue in a project for sam3x. Someone may have a better solution, but it appears the start up code is organised slightly different for sam3s and sam3x.

In the sam3x version, startup_sam3x.s branches to SystemInit in system_sam3x.c and when that returns, branches to __main in main.cpp.

Im guessing that for the sam3s, the function called within system_sam3s.c calls main when its finished setting up the system. If you removed that call it should return back into the assembly file and you can then call main from there

i.e.
Code:
; Reset Handler

Reset_Handler   PROC
                EXPORT  Reset_Handler             [WEAK]
                IMPORT  SystemInit
                IMPORT  __main
                LDR     R0, =SystemInit
                BLX     R0
                LDR     R0, =__main
                BX      R0
                ENDP


Top
 Profile  
 
 Post subject: Re: PLS HELP - undefined reference to 'main'
PostPosted: Wed May 30, 2012 12:02 am 
Offline

Joined: Tue May 15, 2012 11:11 pm
Posts: 9
Quavers,
Thank you very much for the reply. You are the first person to reply to any of my posts in this forum.
I've spent several hours on this and I believe I just got C++ working.

The problem yesterday was that my main.cpp file was not being compiled at all. This was because the project language was C and not C++. I could not find any way to change the project from C to C++ without hacking the cproj file.

Then I had a bunch of configuration that was needed for the C++ compiler in the ToolChain settings, followed by linker configuration. I also had to modify the LinkerScript, to add the bss_start and bss_stop symbols; and also had to enable debugging in the assembler in order to debug.

Again thank you for the help. At this point, I just stepped through a method in the first C++ class that I have running on the SAM3S-EK2 board.

As an aside, I see that I can not step into a constructor. When I try, the cursor stays on the constructor call and never leaves that line. I have to reset the board. I can set a break point in the constructor and can debug upon hitting it. I can also step into methods. But stepping into the constructor isn't working.

I'm using the new Atmel Studio 6. Any idea if this is a bug in Studio 6?

Thanks again,
Paul


Top
 Profile  
 
 Post subject: Re: PLS HELP - undefined reference to 'main'
PostPosted: Wed May 30, 2012 12:42 am 
Offline

Joined: Tue May 29, 2012 9:21 pm
Posts: 3
Im afraid I cant help you there. I havent used Atmel Studio. Currently we are just using the evaluation version of Keil's uVision until we decide which toolchain to use for our upcoming project.


Top
 Profile  
 
 Post subject: Re: PLS HELP - undefined reference to 'main'
PostPosted: Wed May 30, 2012 2:23 am 
Offline

Joined: Tue May 15, 2012 11:11 pm
Posts: 9
Thanks anyway.


Top
 Profile  
 
 Post subject: Re: PLS HELP - undefined reference to 'main'
PostPosted: Fri Jun 01, 2012 9:26 pm 
Offline

Joined: Mon Apr 23, 2012 10:32 am
Posts: 17
Quote:
I also change "int main(void)" to "extern "C" static int main(void)".


Do you know what "static" means in this context ?

By applying it to non-automatic variables and functions, you advice the compiler not to export that name.

No wonder the linker can't find it ...


Top
 Profile  
 
 Post subject: Re: PLS HELP - undefined reference to 'main'
PostPosted: Fri Jun 01, 2012 9:37 pm 
Offline

Joined: Tue May 15, 2012 11:11 pm
Posts: 9
Yes, you are correct.
Though that was not the cause of the problem.
If you read my next post you would have seen what the problem was.
The project was a C project in Studio 6, and thus it did not even compile the main.cpp file.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: