User forums > Embedded development

a problem compiling eeprom of avr(atmega16,winavr) program

<< < (2/7) > >>

MortenMacFly:

--- Quote from: scarphin on August 03, 2011, 09:01:45 pm ---I mean how can the programmer know which compiled library to add after including an include file. I think I'm missing something here.

--- End quote ---
Harhar... sorry to say that, but it's exactly the other way round. You as developer need to know the SDK you are responsible of using it  right. The documentation will tell what file to include and what lib to link against.

Why? Simple: Assume the following two libraries:
[LIB1:]

--- Code: ---int my_calc(int i1, int i2)
{
  int i = i1-i2;
  return i;
}

--- End code ---
[LIB2:]

--- Code: ---int my_calc(int i1, int i2)
{
  int i = i1+i2;
  return i;
}

--- End code ---
Both libs would provide the same function with the same interface. How on earth shall the compiler or linker know, which to link against? It's up to you and will always be up to you to setup your project right. Get used to it or you will sooner or later make serious mistakes.

scarphin:

--- Quote from: MortenMacFly on August 03, 2011, 09:48:05 pm ---
--- Quote from: scarphin on August 03, 2011, 09:01:45 pm ---I mean how can the programmer know which compiled library to add after including an include file. I think I'm missing something here.

--- End quote ---
Harhar... sorry to say that, but it's exactly the other way round. You as developer need to know the SDK you are responsible of using it  right. The documentation will tell what file to include and what lib to link against.

Why? Simple: Assume the following two libraries:
[LIB1:]

--- Code: ---int my_calc(int i1, int i2)
{
  int i = i1-i2;
  return i;
}

--- End code ---
[LIB2:]

--- Code: ---int my_calc(int i1, int i2)
{
  int i = i1+i2;
  return i;
}

--- End code ---
Both libs would provide the same function with the same interface. How on earth shall the compiler or linker know, which to link against? It's up to you and will always be up to you to setup your project right. Get used to it or you will sooner or later make serious mistakes.


--- End quote ---
I have no oppositions to that but that's not quite the case here.

With 'avrlib' (that's the library comes with avrgcc) the programmer needs to the define the mcu and include the 'io.h' file which includes the corresponding header file for the target mcu type according to the mcu definition. And in the case of 'eeprom.h', the eeprom read or write functions are also defined according to the defined mcu type. After all these heavy scripting I don't think it's intended to link the file manually which actually resides in a deeply nested folder. I still think I'm missing something here, I'll check the documentation and try some printf'ing for further investigation.

Aelxx:
@zage2009
Hi, I use C::B during 3 years for AVR programming, it works fine. What you got is probably some problem with paths. Make sure you correctly added avr-gcc to C::B - go to C::B menu \Settings>Compiler and Debugger> in openen window select "GNU AVR GCC compiler", then select tab "Toolchain executables" and check if "Compiler's installation directory" is correct. Do NOT use "Auto-detect"!!!
BTW avr-gcc automatically links to libc.a if it's in the link path.

zage2009:

--- Quote from: scarphin on August 03, 2011, 06:03:27 pm ---U have to add the library '(WinAVR path)\avr\lib\avr5\libc.a' to the 'link libraries' under 'project->build options->linker settings' for ur code to compile. It's quite strange though that the include file doesn't link to the corresponding library.


--- End quote ---

Thank you,your method is correct and the program works well in  my atmega16,of course thanks a lot for other firends' discussions.Another question is  why the same program can be compiled well in avrstudio(an atmel avr IDE) and can't compiled sucessfully in C:B using the same gcc compiler(no especially mannual modification).I guess whether C:B doesn't do well in somewhere.

scarphin:

--- Quote from: Aelxx on August 03, 2011, 11:59:12 pm ---BTW avr-gcc automatically links to libc.a if it's in the link path.

--- End quote ---
Can u explain this in detail pls, how do u manage that exactly?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version