"ld returned 1 exit status"

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

I'm trying to port this https://github.com/nayem-cosmic/... to an ATtiny84A, but when i try to compile this mess it gives me exactly this error: "ld returned 1 exit status" and when i open the build output tab it shows this "undefined reference to main".

I don't know if there is something wrong with the makefile, but i first renamed main.c to main.cpp from Atmel Studio and then added the other files by right clicking the project and clicking Add > Existing item. I attached the project folder

Attachment(s): 

This topic has a solution.
Last Edited: Fri. Mar 2, 2018 - 05:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

See: https://www.avrfreaks.net/forum/tormented-newbie-frequent-error-using-fleury-lcd-code-example

 

Specifically: https://www.avrfreaks.net/comment...

 

And note the importance of using the 'Output' window to see the actual errors!

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

So you are saying that i don't have a main() function, but i do have it in main.cpp

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

No that is not what he's saying. The IMPORTANT thing is to ignore "Error List" completely and look to the "Output" tab to see the REAL reason why the build failed. The "ld" message is just a distant consequence of something that went wrong much earlier.

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

I did look at the output tab, but it gives me nothing useful other than "undefined reference to `main'", here it is:

------ Build started: Project: ATtiny84_RFM69test, Configuration: Debug AVR ------
Build started.
Project "ATtiny84_RFM69test.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Studio\7.0\Vs\Compiler.targets" from project "C:\Users\User\Documents\Atmel Studio\7.0\ATtiny84_RFM69test\ATtiny84_RFM69test\ATtiny84_RFM69test.cproj" (target "Build" depends on it):
	Task "RunCompilerTask"
		Shell Utils Path C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils
		C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils\make.exe all --jobs 2 --output-sync 
		Building target: ATtiny84_RFM69test.elf
		Invoking: AVR/GNU Linker : 5.4.0
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe" -o ATtiny84_RFM69test.elf     -Wl,-Map="ATtiny84_RFM69test.map" -Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mmcu=attiny84a -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.3.147\gcc\dev\attiny84a"  
C:\Users\User\Documents\Atmel Studio\7.0\ATtiny84_RFM69test\ATtiny84_RFM69test\Debug\Makefile(94,1): error: recipe for target 'ATtiny84_RFM69test.elf' failed
		C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATtiny_DFP/1.3.147/gcc/dev/attiny84a/avr25/crtattiny84a.o:../../../../crt1/gcrt1.S:310: undefined reference to `main'
collect2.exe(0,0): error: ld returned 1 exit status
		make: *** [ATtiny84_RFM69test.elf] Error 1
		The command exited with code 2.
	Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreBuild" in project "ATtiny84_RFM69test.cproj" -- FAILED.
Done building project "ATtiny84_RFM69test.cproj" -- FAILED.

Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATtiny_DFP/1.3.147/gcc/dev/attiny84a/avr25/crtattiny84a.o:../../../../crt1/gcrt1.S:310: undefined reference to `main'

OK so that confirms that it was a lack of any main() function in the files that were built in fact. So this is the same error as that other thread.

 

The curious thing there is that it seems to be invoking the linker with no .o files given as input. So that suggests the project had no .c, .cpp or .S files to be built???

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

I was suspecting that because i just added the files without doing anything else and i also renamed main.c to main.cpp so you are probably right, it has no files to build.

If there only was someone who knew how to fix that

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

Show us a picture of what your Solution Explorer currently looks like (with all the branches of the tree expanded)

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

aj22r wrote:
i first renamed main.c to main.cpp

That doesn't sound like a good idea!

 

main.c would be expected to be an ANSI 'C' file;

 

main.cpp would be expected to be a C++ file.

 

 

So, if you started with a project with main.c in it, then it was probably configured as a 'C' project - so unsurprising if it doesn't build C++ properly ... ?

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

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

aj22r wrote:
If there only was someone who knew how to fix that

Rather than try to fix a broken project of unknown history, I generally find it's easier to start again from scratch with a clean slate ...

 

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

That would work too, but i still have the same problem, i'm not experienced enough to get rid of this error even if i started over

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

The point is that if you start over, and do it properly, you shouldn't get the errors.

 

At least if you start over you can then document exactly the steps you took - and we can hopefully see where you're going wrong.

 

Note that Atmel Microchip has a load of tutorials and YouTube videos on how to set up a Studio 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
  1. I create a new project
  2. I rename main.c to main.cpp
  3. I add the other files from Add > Existing item
  4. I compile
  5. Error
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please be more specific - the exact menus, options, and selections.

 

When you create a new project, you have the option of a 'C' project or a C++ project.

 

Have you checked out the tutorials?

 

https://www.microchip.com/avr-su...

 

There's  load of "Getting Started..." videos at the bottom of the page

 

 

EDIT

 

"Episode 7 - Creating a New 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...
Last Edited: Fri. Mar 2, 2018 - 04:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

aj22r wrote:
I create a new project

I rename main.c to main.cpp

Stop RIGHT there. Whey would you ever rename main.c to main.cpp. Back when you start the project you get a choice of "C executable" or "C++ executable". If you plan on using .cpp then you are making the wrong choice. You should select the C++ option.

 

Now in theory it should not matter. Because if Atmel just invoked avr-gcc for everything then it's not just a C compiler it is a "compiler driver" and it know to pass .c files to the C compiler. .S files to the assembler , .o files to the linker and .cpp files to the C++ compiler. But for reasons best known to themselves (so clearly there must be a reason why they did this?) in a project that you select to be "C++ executable" they actually choose to invoke avr-g++ (the C++ compiler) directly. I don't know why but as such it seems fairly important that you made the right choice back when the project was created.

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

Thanks! I can't believe it took me so long to find the option for C++ instead of C, now that particular error seems to be gone, thank you.

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

Well, I did note that back at #9 ...

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

Wow, i didn't even notice that comment