Arduino and Atmel Studio 6.2

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

Hello folks,

 

I have a confusing problem using Atmel with the Arduino - It DID work properly for several projects and then BAM!  The simplest "blink.ino" fails to compile with the msg: undefined reference to 'main'.  I have a few sketches that work well using Arduino ERW but get the same error:  undefined reference to 'main' when I use Atmel Studio.

 

i use Atmel Studio b/c i have issues with 2 MEGAS which will not work on the USB port for programming so the ISP programmer works for these two units. 

 

I've gone through un-installing and reinstalling - i did some reading but cannot find the FIX (or missed it somewhere).

 

My programming skills are out of date and a bit rusty - I did coding back in the 80's ... it's been a challenge doing some 'catch-up'

 

I'm working on understanding C++ so some help sorting out this would be greatly appreciated.

 

Eddie

 

 

Last Edited: Sun. Nov 16, 2014 - 02:07 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Eddie, you posted in the UC3 forum. Thread now moved to the Arduino forum.

 

If you have further questions which are Arduino related please post here.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Thanks for the course correction :)

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

Don't know much about your problem as I don't use AS6.x however, as you may know, the Arduino setup consists of 2 "functions" setup and loop, no main as such as in a standard C program.

 

So if you use the standard compiler you get the the above error. I think there is some add on to AS to make it behave like the Ardino IDE but someone else will need to chime in with that.

I did coding back in the 80's

ahhh the good old days.... wink

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Yup ... I had the same thought ... no main() is used in Arduino IDE .. so that's where it gets weird.

 

doesn't make allot of sense.  I tried to dig around a bit more to find info on this goofy error - nothing as of yet.

 

It could be better if the IDE followed the old style 'c' in some respects - have had good luck w/most of the stuff I've written.

 

Thanks,

Eddie

Last Edited: Sun. Nov 16, 2014 - 11:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The simplest "blink.ino" fails to compile with the msg: undefined reference to 'main'.  I have a few sketches that work well using Arduino ERW but get the same error:  undefined reference to 'main' when I use Atmel Studio.

You don't mean you are simply typing:
 

void setup() {
  // something
}

void loop() {
  // something else
}

into a .cpp file in a Studio C++ project and expecting it to work are you? Of course something like this will give a link error about "main undefined" because there is no function called main(). You cannot just write INO files in Studio and expect it to work!

 

Now Studio has an add on called "Visual Micro" and (while I haven't tried it) I believe that *will* let you just use INO sketch files in Studio. But Studio on its own will not allow this.

 

The other way to do it (to use Arudino code in Studio) is to write a "wrapper" that, like Arduino's main wrapper, calls setup() and then calls loop() repeatedly but to use the Arduino library code you also need a pre-built copy of libcore.a for the target micro - there are many tutorials on the net (that will include the term "libcore.a") that will tell you how to do this. But "Visual Micro" might be easier.

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

I am actually using the Atmel Studio's Arduino IDE interface ... my C++ is, on my best day, pretty poor.  I am still playing 'catch up'.  Had formal training in assembler, basic, c, cobol, dbase and a couple of other ancient languages - still getting my head wrapped around the C++ stuff.  Arduino is pretty much basic 'C' coding for me so that's simple.

 

I've taken several "Arduino" sketches that compile and run properly then open  a new sketch in Atmel Studio ... copy the same working sketch there and Poof - it's a crap shoot - sometimes Atmel Studio works perfectly.   I can upload the code using the tinyISP and everything is well.

 

A couple of days later ... BAM!  Atmel Studio just refuses to compile anything properly ... It reports the error: undefined reference to 'main'

 

so that is where I'm at with this.  It works and then doesn't work.

 

Apparently I am chasing a bug I cannot readily reproduce - these are the ones that drive most of us just a bit bonkers.

 

Unless I drop a bunch of bucks on this and then have the authors sort it out, I have to inquire to y'all to see where I might find this mysterious little bugger.

 

Thanks,

Eddie

Last Edited: Mon. Nov 17, 2014 - 10:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Atmel Studio's Arduino IDE interface .

Never heard of it - what is that - do you mean the VisualMicro add-on?

A couple of days later ... BAM!  Atmel Studio just refuses to compile anything properly ... It reports the error: undefined reference to 'main'

Do you know how Arduino works? As well as the sketch you write there is a "hidden" file:

uid23021@lxl0131u:~/windows/Program Files/Arduino/hardware/arduino/cores/arduino$ cat main.cpp
#include <Arduino.h>

int main(void)
{
	init();

#if defined(USBCON)
	USBDevice.attach();
#endif
	
	setup();
    
	for (;;) {
		loop();
		if (serialEventRun) serialEventRun();
	}
        
	return 0;
}

That is what calls setup() and loop() in the sketch you wrote. As you can see this is what provides the main: that the linker is not finding when you build.

 

Now I have never used this Visual Micro add-on (assuming that is what you are using) but I guess that, like the Arduino IDE itself, it also has access to this Arduino/hardware/arduino/cores/arduino/main.cpp and it builds this in "above" the code you write. So if main: is not found it suggests this file is damaged/lost or something like that. It is a bit curious that there isn't a compilation error earlier on but I guess that if, for example, you still had this file but you #if 0'd it then that would allow the thing to build without warning/error but fail at the link stage.

 

I would just download the add-on for Studio myself but I've heard form others it's a bit like a pernicious virus in that once you have got it, it keeps throwing "nag" screens asking for money and it's very difficult to stop it. So I have been avoiding it so far. I guess I could try a VM snaptshot, install it, understand how it operates then revert the snapshot.

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

Hi - Yes, that's correct ... Visual Micro ADD-ON.  Now this makes sense.  So now the search is on me to see where or if something is not being found on my machine.  This seems to be the obvious next step.

 

I code to what is available in the libraries and check first time builds against the Arduino compiler.  I'd say in the past that I'd write LIBRARY code, stick it into a library where the compiler can find it and that's how it worked, well back when ... things have changed in this environment.

 

as far as nag screens?  It tosses one at start-up, begs for funds but closing it out it doesn't keep popping up.  That's what I've experienced here.

 

The Arduino interface is okay but lacks some abilities.  I've become accustomed to Microsoft product (C/C++ v7, MS VB, MS VC) shortcut keys, editor behavior and the like. 

Arduino using JAVA ... yes, it works but seems to lack some considerations like always giving you a tiny little screen to start with, etc. 

I still have and occasionally use DOS based MS (asm, basic &'C') and Borland stuff too. 

 

I found some Arduino compiler shortcomings - one notably was failing with more than 15 CASES in a SWITCH (something like that) - I2C communications project.

 

I'll pay close attention to what's going on and with this new understanding "HOW IT WORKS" I should be able to find out why it "goofs up" from time to time.

 

I'll keep y'all posted if I find out exactly what is going on. 

 

Other ideas or observations are always welcome! :)

 

Thanks for your assist!

Eddie

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

It sounds as if you have been fiddling with the Arduino locations in the Visual Micro configuration.

 

From memory,    when you first install VisualMicro,  it looks in the usual places for the active Arduino installation.     And makes a note of them.

 

So it can build a regular Arduino sketch from the regular Arduino 'user directory' and link with libraries from the regular Arduino libraries directory.

And the 'VM' project is built from within AS6.2.

 

I suspect that you have altered these locations.     Edit them back to the original Arduino values.

 

Apart from a Terminal that works in AS6.2 and a different editor,     I don't see much advantage over the regular Arduino IDE.

You don't get JTAG or debugWIRE debugging with either arrangement.

 

If you pay money to VM,    I think that you get some form of "printf" debugging.

 

There are 'other' Arduino+AS6.2 arrangements that enable you to write regular C++ projects that link with Arduino libraries.      Then you get regular JTAG / debugWIRE / Simulator debugging.

 

David.

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

There are 'other' Arduino+AS6.2 arrangements that enable you to write regular C++ projects that link with Arduino libraries. 

For tutorials about doing that google "studio arduino libcore.a"

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

Hi

 

Many thanks for the guidance. 

 

One good point about locations ... I've avoided moving and/or renaming anything b/c lack of experience with AS and extensive experience with what happens when one MOVES or CHANGES things with the LACK of experience.  I have the BITE MARKS to prove it - LOL.  So - it's better left where it expects things to be found.  This also leads me to where *IT* wants to be found.  OK - I will investigate this a bit deeper.  I might have an idea what could be going on.

 

Hmmm - better IDE interface - interesting.  I will definitely consider that when I can solve the first problem ... no sense piling problems on problems right now.

 

David, I'm getting my head wrapped around C++ but have a good background in 'C' so it's not too difficult but will take some free time to digest it all.

 

Yup - when i uninstalled everything and started with AS first, it did complain about not finding Arduino .. so in earnest I made the course correction.

 

I have AS on several different machines - Win 8, Win 7, XP, XPx64 - it doesn't seem to like Win 2K or earlier - LOL!

 

Thanks again for your input - greatly appreciated :)

Eddie

 

 

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

This laptop runs Vista-32.    AS6.2 is fairly unusable.

My old XP desktop machine is sitting in a cupboard.     Since it was a lot slower than the laptop,    I cannot imagine it running AS6.2 at all.

 

So I can only guess that your Win 2k machine would be totally unusable from a speed point of view.     (regardless of the operating system facilities)

 

Of course,    I can run uVision5 or Rowley Crossworks quite happily on Vista-32.

 

AS6.2 'needs' a fast PC.    It runs ok on my Win 7 desktop.

 

David.

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

 

See also Visual Micro used  with the new FREE Microsoft Visual Studio Community software product.

 

Last Edited: Thu. Nov 20, 2014 - 07:50 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That resulted in a double take.

Thank you!

The Next Web

Microsoft open-sources .NET framework and offers Visual Studio Community 2013 for free

by

2014-Nov-12

http://thenextweb.com/microsoft/2014/11/12/microsofts-open-sources-net-makes-visual-studio-community-2013-free-everyone/

"Dare to be naïve." - Buckminster Fuller

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

No worries ... I believe I located my particular problem.

 

I copied some files from GitHub ... bad move b/c 'SAVE AS' gave me a copy of the webpage (I didn't think to check - it's been a hard week @ work) - OK.  Got the correct files and TRIED TO replace the files ... WINDOWS totally refused to replace the files correctly with the NEW files (kept leaving the OLD wrong version).  NEXT MOVE: Delete all the files & folder.  Try to copy it from "D:" to "C:" ... NOPE!  Refused to work ... had the same files I just DELETED!!!  (yep, I checked the files I was trying to copy) Bloody hell!  Hmmmmm - time to flush the HARD DRIVE BUFFERS - so a COLD START (flipped off the UPS).

 

MICROSOFT seems to be the problem on MY end. 

 

Now after finally getting the stupid computer to do what it should have done the FIRST time (I've NEVER seen this happen before) ... test the new library files using ARDUINO and ARDUINO ERW - **SUCCESS**  cool.

 

Hang on ... this gets REAL screwy. 

 

Started AS and opened the sketch.  Tried to BUILD it ... Somehow it found a copy of the BAD header file!!!  This is AFTER I deleted every known copy of it ... I checked the ARDUINO LIBRARIES and those files are OKAY.

 

So - Now the question is when using the Arduino IDE in Atmel Studio ... Can I assume it looks into the "LIBRARY" folder(s) pointed to by the Arduino or Arduino ERW? 

 

If so --- seems i have a serious problem here w/this particular machine.  See Windows RUN ... See PC crawl!  Microsoft = Mature Malware.

 

Where would I be able to determine which folder AS is looking in?  I'm trashing this Windows 8 for Win 7 - at least it is predictable.

 

I am going to try this on the XP-x64 machine (dual quad core XEON 16GB)

 

Any other observations would be appreciated.

 

Thanks,

Eddie

 

 

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

Okay!!! I found the Atmel Studio problem and it was hardware AND software related but NOTHING directly to do with Atmel Studio or Arduino.

 

This makes sense and HERE IS WHY:

I don't normally turn my PC off - I put it into SLEEP MODE - either way it draws almost the same amount of power (as viewed by my APC UPS and FLUKE Amp Probe).

If you wonder why your PC draws power while you know you turned it off:  It always draws power for the STANDBY +5v devices inside your machine.

the ONLY true way to make sure your PC (and electric bill) is truly "OFF" is to either turn off the switch on the back of the machine's power supply (if you have one) OR use a power strip with an ON/OFF switch or UNPLUG your PC from the wall outlet.

 

I don't know exactly when PC's began to be manufactured with STANDBY power supplies but I personally recall them as early as 2000.  Today they are common place.

 

After doing some research on WHY the above problem existed (my PREVIOUS POST), I did some checking (and got lucky) on what the heck was running. 

 

OOOOOOOhhhh .... DISKEEPER DiskExpress 'Hard Drive Caching'.  Apparently a "GIFT" from either Acer, Condusiv or MickeySoft. 

 

BADA BING! 

 

Un-installed it.  PROBLEM SOLVED! 

 

If you don't understand what a disk caching program does and why it must behave itself at ALL TIMES:

It is a small little program that caches data from the hard drive and keeps it in RAM for FASTER retrieval instead of constantly accessing the hard drive.

 

This particular version DID NOT play nice with my "C:" drive because it is a Solid State Drive (or SSD).  NOTE: It DOES work perfectly for conventional Hard Drives.  I use SSD for the OS and programs but I use 2 conventional hard drives (8TB) for long term data storage (along with another 16TB on 2 servers and LTO3 tape backup).

 

My previous Post was copying from an SSD drive to itself into another folder. 

Apparently there is a CACHE involved on the SSD so it confused Diskeeper software and kept copying the wrong data. 

 

THIS also added to the Atmel Studio problem where it would work fine ONE DAY and absolutely refuse to work DAYS LATER.  The DISK CACHING program was not designed for the SSD drive so it had BAD information (either from the drive or from the disk cache).

 

I have not investigated a software based solution because most SSD drives are just that bloody fast so they don't really need external CACHING - maybe someone else has?  DO SHARE!

 

So with this NEW knowledge I hope others can find the answer to similar problems. 

If it worked before and doesn't now *AND* you haven't changed any operational settings - LOOK for Programs or "SERVICES" that your PC is running.

Check their PROPERTIES before you start disabling or uninstalling them.  MANY of these are necessary for any PC to startup and run properly.

You might find the culprit there.

 

Thanks to y'all for your help.  Hope I was able to return the favor.

Eddie

 

Last Edited: Fri. Nov 28, 2014 - 03:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

RGB_Mixer wrote:

If so --- seems i have a serious problem here w/this particular machine.  See Windows RUN ... See PC crawl!  Microsoft = Mature Malware.

 

Any other observations would be appreciated.

 

Yes... what Intel giveth, Microsoft taketh away!!!

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston