Is it Codeblocks or my gcc-avr

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

I'm using Code::Blocks as my IDE and whenever I try to build a project I get this series of errors:

main.c|1|error: avr/io.h: No such file or directory|
main.c||In function ‘main’:|
main.c|16|error: ‘DDRB’ undeclared (first use in this function)|
main.c|16|error: (Each undeclared identifier is reported only once|
main.c|16|error: for each function it appears in.)|
main.c|22|error: ‘PORTB’ undeclared (first use in this function)|
||=== Build finished: 5 errors, 0 warnings ===|

I've read where this could be caused by an old gcc version in Ubuntu, so I tried to remove and reinstall mine apparently to no avail, though. Can anyone help me out?

Thanks!

Oh yeah, I'm using the led project from this post https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=38735

IDE - Eclipse w/AVR Eclipse plugin
Programmer - AVRISP MKII
OS - Ubuntu (Intrepid) Linux

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

Of the errors only the first one is meaningful. The rest are derivatives from that one.

Your include path is propably incorrect.

Has the project compiled cleanly before ?

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

The way it knows the declaration for DDRB is that your .c file will have a:

#include 

near the top and then in your Makefile the CPU target type will be specified and this will lead to that model number being passed in a -m to the compilation. That will lead to a compiler internal define being made and that will be used inside io.h to select the correct io.h file being pulled into the build that holds the define for DDRB.

For example in an Mfile generated Makefile the following may appear:

MCU = atmega128

then the compiler invocation uses:

ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)

so the compiler invocation will include:

-mmcu=atmega128

This will lead to __AVR_ATmega128__ internally being defined and in io.h it has:

#elif defined (__AVR_ATmega128__)
#  include 

Which is why io.h, this time, leads to the 128 specific IO definitions being used and within that is:

/* Data Direction Register, Port B */
#define DDRB      _SFR_IO8(0x17)

So you may want to trace this path yourself and find out which part of it is not correctly working in your specific case.

Cliff

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

I think I got my path fixed, well I changed it and now get a new error anyway.

Here it is:

/usr/local/avr/lib/gcc/avr/4.2.2/../../../../avr/include/avr/io.h|301|warning: #warning "device type not defined"|
main.c||In function 'main':|
main.c|16|error: 'DDRB' undeclared (first use in this function)|
main.c|16|error: (Each undeclared identifier is reported only once|
main.c|16|error: for each function it appears in.)|
main.c|22|error: 'PORTB' undeclared (first use in this function)|
||=== Build finished: 4 errors, 1 warnings ===|

I've searched for the path on the first line, but I just can't seem to find it or where to change it. However, codeblocks does display the file and shows it to be in this path

/usr/local/avr/avr/include/avr/io.h

. My codeblocks version is SVN 5093.

Should I just use a different IDE instead or keep trudging along with it and get it to work?

IDE - Eclipse w/AVR Eclipse plugin
Programmer - AVRISP MKII
OS - Ubuntu (Intrepid) Linux

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

But THIS is your error that you need to fix:

device type not defined

define the device (so it reaches the compiler as a -mmcu= value) and all will be well.

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

The "device type not defined" warning is exactly what clawson mentioned - you haven't passed the -mmcu setting to the compiler. It's also quite possible that you're using your native gcc compiler instead of the avr-gcc cross compiler - at least for me, avr-gcc includes the proper path for the avr-libc headers by default.

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

I have set -mmcu and it's set in the Makefile as well. I think Lonetech might be on to something because it seems I have multiple installations of avr-gcc and I think I should remove all of them and start over. I've tried to use apt-get purge but I still see avr directories all over the place. Do I just need to go in and rm them? Then after my system is clean of avr, do I follow the stickied guide to install it or pull it from the repositories?

IDE - Eclipse w/AVR Eclipse plugin
Programmer - AVRISP MKII
OS - Ubuntu (Intrepid) Linux

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

Quote:
I have set -mmcu and it's set in the Makefile as well.

Can you post the entire build output including the lines that actually invoke the compiler? I'll bet -mmcu= does not appear there!

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

I'm not sure if this is what you are looking for but it's all I know how to get so far aside from what I've already posted:

In file included from main.c:1:
avr-gcc -gdwarf-2 -DF_CPU=16000000UL  -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=main.lst  -std=gnu99  -Wl,-Map=main.map,--cref    -lm  main.c   -o main
/usr/local/avr/lib/gcc/avr/4.2.2/../../../../avr/include/avr/io.h:313:6: warning: #warning "device type not defined"
main.c: In function 'main':
main.c:16: error: 'DDRB' undeclared (first use in this function)
main.c:16: error: (Each undeclared identifier is reported only once
main.c:16: error: for each function it appears in.)
main.c:22: error: 'PORTB' undeclared (first use in this function)
make: *** [main] Error 1
Process terminated with status 2 (0 minutes, 0 seconds)
4 errors, 1 warnings
 

IDE - Eclipse w/AVR Eclipse plugin
Programmer - AVRISP MKII
OS - Ubuntu (Intrepid) Linux

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

javafiend wrote:
I'm not sure if this is what you are looking for but it's all I know how to get so far aside from what I've already posted:

That gives an idea what how your compiler is called. Good!

Quote:

In file included from main.c:1:
avr-gcc -gdwarf-2 -DF_CPU=16000000UL  -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=main.lst  -std=gnu99  -Wl,-Map=main.map,--cref    -lm  main.c   -o main


The compiler and me are missing a -mmcu=at... If this is visible at the command line of the compiler the io.h finds what it needs.
Maybe you send the Makefile to see what happens there.

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

Quote:

I have set -mmcu and it's set in the Makefile as well. I think Lonetech might be on to something because it seems I have multiple installations of avr-gcc and I think

What version of avr-gcc are you using. On Windows I know I have seen reports of an older version of avr-gcc having this problem together with C::B.

I am seeing this problem myself but have not bothered to fight it to the end as the whole C::B manouvre was just a playaround thing. I'm on Windoze when it comes to AVR development and use mainly AVR Studio. (The point with trying out C::B was to have an alternative IDE that is better on the points where Studio is really weak: The Editor intellisense , smart cursor movement and indentation etc).

Anyway: Are you using an old version of avr-gcc/avrlibc?

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

I cleaned avr-gcc and codeblocks completely off of my system (I think anyway) and did a fresh install. I still get the errors I was previously but it seems like only when I try to use a custom Makefile. When I don't specify one, I get a good build with an LED test program. The program I'm concerned with still gets errors that look like they're related to the custom includes.

Here's the error

-------------- Build: Photovore_v1 in Photovore_v1 ---------------

Compiling: Photovore_v1.c
Linking console executable: bin/Debug/Photovore_v1.elf
obj/Debug/Photovore_v1.o: In function `main':
/home/badger/Documents/AVRprojects/Photovore_v1/Photovore_v1.c:41: undefined reference to `a2dInit'
/home/badger/Documents/AVRprojects/Photovore_v1/Photovore_v1.c:42: undefined reference to `a2dSetPrescaler'
/home/badger/Documents/AVRprojects/Photovore_v1/Photovore_v1.c:43: undefined reference to `a2dSetReference'
/home/badger/Documents/AVRprojects/Photovore_v1/Photovore_v1.c:56: undefined reference to `a2dConvert8bit'
/home/badger/Documents/AVRprojects/Photovore_v1/Photovore_v1.c:57: undefined reference to `a2dConvert8bit'
Process terminated with status 1 (0 minutes, 0 seconds)
5 errors, 0 warnings
 

IDE - Eclipse w/AVR Eclipse plugin
Programmer - AVRISP MKII
OS - Ubuntu (Intrepid) Linux

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

javafiend wrote:
The program I'm concerned with still gets errors that look like they're related to the custom includes.

That has nothing to do with an include. We left the area of compiling and entering the state of linking. Now the whole project is checked if there all variables, functions are defined. And there are some missing.

Quote:

Compiling: Photovore_v1.c
Linking console executable: bin/Debug/Photovore_v1.elf
obj/Debug/Photovore_v1.o: In function `main':
/home/badger/Documents/AVRprojects/Photovore_v1/Photovore_v1.c:41: undefined reference to `a2dInit'
/home/badger/Documents/AVRprojects/Photovore_v1/Photovore_v1.c:42: undefined reference to `a2dSetPrescaler'
/home/badger/Documents/AVRprojects/Photovore_v1/Photovore_v1.c:43: undefined reference to `a2dSetReference'
/home/badger/Documents/AVRprojects/Photovore_v1/Photovore_v1.c:56: undefined reference to `a2dConvert8bit'
/home/badger/Documents/AVRprojects/Photovore_v1/Photovore_v1.c:57: undefined reference to `a2dConvert8bit'
Process terminated with status 1 (0 minutes, 0 seconds)
5 errors, 0 warnings 


Just from reading the names I guess that a module to handle the analog to digital converter is not included into your project. :wink: So the (compiler) linker tells you in detail which module (Photovore_v1.c) which line (42, 43, 56, 57) causes the problems. Not that difficult... :shock:

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

Ok, I think I got it now. A rookie mistake on my part I guess.

Thanks,kschwiRG, for suggesting that the included file weren't in my project. I was under the assumption that by merely including them, they would be found. So I added the errant files to my project.

Thanks again, everyone, for enduring my noobishity and helping get my environment up and running.

IDE - Eclipse w/AVR Eclipse plugin
Programmer - AVRISP MKII
OS - Ubuntu (Intrepid) Linux