Atmel Studio Error with Code Ported From Arduino: "ld returned 1 exit status"

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

hello

 

What's causing this error?

 

i'm trying to compile some code for an ATTiny85 on a bare board, using Atmel Studio 7, with a JTAGICE3 (see pic below).

But Atmel Studio complains:

Severity Code Description Project File Line

Error ld returned 1 exit status pwm-test collect2.exe 0

Atmel Studio seems to recognize the ATTiny85 with no problem (image below).

The code compiles fine in Arduino IDE, on same computer, and uploads runs with no problem on a Digispark. 

 

Based on what i've read so far, i think cause might be one of the following, but i don't know how to fix:

  • Based on filename, Studio is compiling for the wrong language (gcc vs c?). I created the project as a "GCC C Executable Project". The file is saved as main.c
  • or it can't find a library. 

 

My code is below. 

Thx!

 

 

 

#define F_CPU 8000000
#include <avr/io.h>
#include <util/delay.h>

// Starting pw's for red, green and blue
uint8_t RedBrightness=0, WhiteBrightness=85, BlueBrightness=170;
uint8_t RedLED = 1, WhiteLED = 4, BlueLED = 0;

void setup() {
    TCCR0A = 2<<COM0A0 | 2<<COM0B0 | 3<<WGM00;
    TCCR0B = 0<<WGM02 | 1<<CS00;
    TCCR1 = 0<<PWM1A | 0<<COM1A0 | 1<<CS10;
    GTCCR = 1<<PWM1B | 2<<COM1B0;
}

void loop() {
    if (++RedBrightness>255) RedBrightness=0;
    if (++WhiteBrightness>100) WhiteBrightness=0;
    if (++BlueBrightness>100) BlueBrightness=0;

    analogWrite(BlueLED, BlueBrightness );
    analogWrite(RedLED, RedBrightness);
    analogWrite(WhiteLED, 100 - WhiteBrightness);

    _delay_ms(30);
}

 

This topic has a solution.

Last Edited: Fri. Jan 5, 2018 - 12:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sometimes Atmel Studio filters the actual build output a little too much before presenting it in the list of warnings and errors.

 

We'd like to see the complete build output. Do this:

 

1. Do a Rebuild (which is a clean followed by a build)

2. Switch to the Output tab

3. Mark all the text in that tab and copy it

4. Paste in a post here

 

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

JohanEkdahl wrote:
Do a Rebuild (which is a clean followed by a build)

 

Thx, Johan. But do i pick "Rebuild Solution", or "Rebuild pwm-test"?

(pwm-test is the name of the project)

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

johnyradio wrote:
What's causing this error?

That error is, basically, just the final conclusion that, "the link failed"

 

That will be due to other error(s) earlier in the build - so, as JohanEkdahl said, you need to post the full build output.

 

 

The code compiles fine in Arduino IDE,

So how, exactly, did you get it into Atmel Studio?

 

You have to follow the proper "import" procedure ...

 

gcc vs c?

GCC is the compiler[1] - it supports both C and C++ languages

 

  • I created the project as a "GCC C Executable Project". The file is saved as main.c

No - you need to do "create from Arduino sketch" or somesuch...

 

or it can't find a library. 

Doing the proper Arduino import should ensure that it also imports all the required libraries

 

 

[1] Well, actually, "GCC" includes more than just the compiler ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think "Rebuild Solution" should rebuild all the projects in the solution ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
you need to do "create from Arduino sketch"

 

i simply pasted the code into the new Studio project, overwriting the default Studio code. 

 

i didn't do "Create from Arduino sketch" because there's no ATTiny board listed. This code runs on a Digispark, which is based on the ATTiny85.

 

Last Edited: Fri. Jan 5, 2018 - 11:11 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Output from Rebuild Solution:

------ Rebuild All started: Project: pwm-test, Configuration: Debug AVR ------

Build started.

Project "pwm-test.cproj" (Clean target(s)):

Target "Clean" in file "D:\Program Files (x86)\Atmel\Studio\7.0\Vs\Compiler.targets" from project "D:\Documents\Learn\Atmel Studio\pwm-test\pwm-test\pwm-test.cproj" (entry point):

Using "RunCompilerTask" task from assembly "D:\Program Files (x86)\Atmel\Studio\7.0\Extensions\Application\AvrGCC.dll".

Task "RunCompilerTask"

Shell Utils Path D:\Program Files (x86)\Atmel\Studio\7.0\shellUtils

D:\Program Files (x86)\Atmel\Studio\7.0\shellUtils\make.exe clean 

rm -rf  main.o   

rm -rf  main.d   

rm -rf "pwm-test.elf" "pwm-test.a" "pwm-test.hex" "pwm-test.lss" "pwm-test.eep" "pwm-test.map" "pwm-test.srec" "pwm-test.usersignatures"

Done executing task "RunCompilerTask".

Done building target "Clean" in project "pwm-test.cproj".

Done building project "pwm-test.cproj".



Build succeeded.

------ Rebuild All started: Project: pwm-test, Configuration: Debug AVR ------

Build started.

Project "pwm-test.cproj" (default targets):

Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').

Target "CoreBuild" in file "D:\Program Files (x86)\Atmel\Studio\7.0\Vs\Compiler.targets" from project "D:\Documents\Learn\Atmel Studio\pwm-test\pwm-test\pwm-test.cproj" (target "Build" depends on it):

Task "RunCompilerTask"

Shell Utils Path D:\Program Files (x86)\Atmel\Studio\7.0\shellUtils

D:\Program Files (x86)\Atmel\Studio\7.0\shellUtils\make.exe all --jobs 2 --output-sync 

Building file: .././main.c

Invoking: AVR/GNU C Compiler : 5.4.0

"D:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe"  -x c -funsigned-char -funsigned-bitfields -DDEBUG  -I"D:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.3.147\include"  -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=attiny85 -B "D:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.3.147\gcc\dev\attiny85" -c -std=gnu99 -MD -MP -MF "main.d" -MT"main.d" -MT"main.o"   -o "main.o" ".././main.c" 

Finished building: .././main.c

.././main.c: In function 'loop':

D:\Documents\Learn\Atmel Studio\pwm-test\pwm-test\main.c(64,5): warning: implicit declaration of function 'analogWrite' [-Wimplicit-function-declaration]

     analogWrite(BlueLED, BlueBrightness );

     ^

Building target: pwm-test.elf

Invoking: AVR/GNU Linker : 5.4.0

"D:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe" -o pwm-test.elf  main.o   -Wl,-Map="pwm-test.map" -Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mmcu=attiny85 -B "D:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.3.147\gcc\dev\attiny85"  

D:\Documents\Learn\Atmel Studio\pwm-test\pwm-test\Debug\Makefile(108,1): error: recipe for target 'pwm-test.elf' failed

D:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATtiny_DFP/1.3.147/gcc/dev/attiny85/avr25/crtattiny85.o:../../../../crt1/gcrt1.S:310: undefined reference to `main'

collect2.exe(0,0): error: ld returned 1 exit status

make: *** [pwm-test.elf] Error 1

The command exited with code 2.

Done executing task "RunCompilerTask" -- FAILED.

Done building target "CoreBuild" in project "pwm-test.cproj" -- FAILED.

Done building project "pwm-test.cproj" -- FAILED.



Build FAILED.

========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

 

Last Edited: Fri. Jan 5, 2018 - 11:08 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

awneil wrote:

you need to do "create from Arduino sketch"

 

 

johnyradio wrote:
i simply pasted the code into the new Studio project, overwriting the default Studio code.

No, that won't work.

 

You do need to do "create from Arduino sketch" - so that it also gets all the associated libraries, etc.

i didn't do "Create from Arduino sketch" because there's no ATTiny board listed. 

Hmm ... actually the only time I've used this import feature was for an ATTiny project!

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
Hmm ... actually the only time I've used this import feature was for an ATTiny project!

 

What board/device should i pick?

Last Edited: Fri. Jan 5, 2018 - 11:25 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

All of those errors are things that the Arduino "import" process addresses for you:

Building file: .././main.c

The Arduino "language" is C++; so probably better to name it main.cpp

 

D:\Documents\Learn\Atmel Studio\pwm-test\pwm-test\main.c(64,5): warning: implicit declaration of function 'analogWrite' [-Wimplicit-function-declaration]

That's it not finding one of the Arduino Libraries.

 

D:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATtiny_DFP/1.3.147/gcc/dev/attiny85/avr25/crtattiny85.o:../../../../crt1/gcrt1.S:310: undefined reference to `main'

All C programs are required to have a function named main() as their entry point.

 

The Arduino framework provides this for you

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
Try this: https://forum.arduino.cc/index.p...

 

Thx, that helped! The sketch imported ok through "Create project from Arduino sketch" when i picked Gemma. I can see there are many more files and stuff in the project now. When i do a "Build" or "Rebuild", i get "Build Succeeded". 

 

I don't know if it matters, but i did not change the config of the sketch to Gemma in the Arduino IDE-- it's still set to Digispark. 

 

Thx for finding that option! and thx for analysis of build output. 

Last Edited: Fri. Jan 5, 2018 - 12:03 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You're welcome!

 

You can now mark the thread as solved: https://www.avrfreaks.net/comment...

 

johnyradio wrote:
I don't know if it matters, but i did not change the config of the sketch to Gemma in the Arduino IDE

I don't think it does - AS just takes what you tell it in the import form.

It just copies everything - doesn't touch the original Arduino stuff.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
It just copies everything - doesn't touch the original Arduino stuff.

but doesn't Arduino IDE change hidden properties of the sketch if i pick a different device in Arduino IDE?

 

thx

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

awneil wrote:
You can now mark the thread as solved: https://www.avrfreaks.net/comment... 

Err - you didn't follow those instructions: use the 'Mark Solution' button!

 

doesn't Arduino IDE change hidden properties of the sketch if i pick a different device in Arduino IDE?

presumably, yes; but, AIUI, the AS import creates a completely new & independent set of files - it doesn't retain any link to the original Arduino sketch, or the Arduino IDE installation.

 

 

EDIT

 

Ah - you found the 'Mark Solution' button while I was typing!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Fri. Jan 5, 2018 - 12:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
it doesn't retain any link to the original Arduino sketch

i'm not saying it retains any "link" or touches the original. Simply that it imports all settings and libraries. If i pick a different device in Arduino IDE, then something different will get imported by AS.

 

Correct?

Last Edited: Fri. Jan 5, 2018 - 12:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't know.

 

You'd have thought that AS could get all the information it needed from the Arduino settings - without you having to manually specify the board & chip ...

 

Maybe?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
without you having to manually specify the board & chip ...

 

you think that the import will be identical, whatever device i have selected  in the Arduino IDE (not in AS). 

Last Edited: Fri. Jan 5, 2018 - 12:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

johnyradio wrote:
you're saying that it's not necessary to select the device in the Arduino IDE (not in AS)

No, I'm not saying that.

 

I'm saying that it seems that it should be possible for AS to deduce the board & chip from the Arduino IDE without having to manually specify them to AS during the import process.

 

you think that the import will be identical, whatever device i have selected in the Arduino IDE?

I don't know.

 

And I don't know what happens if you lie to AS and tell it something completely different from what you set in the Arduino IDE

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
I don't know what happens if you lie to AS

but it's a white lie laugh