CodeVisionAVR C-compiler redefined linker errors

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

I have switched to CodeVisionAVR recently.
The 1.25.9 version compiles my (hobby) project.
Now there is version 2.03.3 of cvavr.
It looks like version 2 is no improvement on the older version, as it is not capable to compile the same project.
The hpinfotech crew seem to have no clue.

But the people over here are more clever. :-)

In an include file (.h) I have for example this:

flash unsigned short Table[]={
42, 46, 50, 54, 60, 66, 72
};

or

unsigned int Table2[]={
42, 46, 50, 54, 60, 66, 72
};

The compiler comes with:
Linker error: bla.h(xx): entry 'Table' redefined

How can I solve it?
I have already used:

#ifndef __INCLUDE_H
#define __INCLUDE_H

blahblah

#endif /* __INCLUDE_H */

Thank you very much for any help.

The alternative is of course to stick with the older compiler.

Jack.

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

you don't put definitions in header files because if you include the header more than once, anything defined in the header will generate a re-definition error. [it ifdef does not protect you against this, it only does so if all the files are in the same compilation unit]

Place the tables in a .c file, and then declare the tables using "extern"

in .h file

extern flash unsigned short Table[];
extern unsigned int Table2[];

in .c file

flash unsigned short Table[]={
42, 46, 50, 54, 60, 66, 72
};

unsigned int Table2[]={
42, 46, 50, 54, 60, 66, 72
};

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

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

glitch wrote:
you don't put definitions in header files because if you include the header more than once, anything defined in the header will generate a re-definition error. [it ifdef does not protect you against this, it only does so if all the files are in the same compilation unit]

Place the tables in a .c file, and then declare the tables using "extern"

in .h file

extern flash unsigned short Table[];
extern unsigned int Table2[];

in .c file

flash unsigned short Table[]={
42, 46, 50, 54, 60, 66, 72
};

unsigned int Table2[]={
42, 46, 50, 54, 60, 66, 72
};

That's a quick response, thank you very much!
I'll try it.

Jack.

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

Just to be clear... the .c portion is only done in one file only. The extern declaration allows other .c files to access the data once the compiler links everything together.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

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

Even the infinitely-more-clever people here (obviously more so than the compiler-writer himself [?] ) will need more information.

Reduce the problem to the smallest complete program and post it. It looks like this will need a .c and a .h.

In general, most here would never structure a program as I can see from the sketchy details above.

foo.h:

extern flash unsigned short Table[];

foo.c:

#include "foo.h"
flash unsigned short Table[]={
42, 46, 50, 54, 60, 66, 72
};

main.c:

#include "foo.h"
...
fred = Table[4];
...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

theusch wrote:
Even the infinitely-more-clever people here (obviously more so than the compiler-writer himself [?] ) will need more information.

Reduce the problem to the smallest complete program and post it. It looks like this will need a .c and a .h.

In general, most here would never structure a program as I can see from the sketchy details above.

foo.h:

extern flash unsigned short Table[];

foo.c:

#include "foo.h"
flash unsigned short Table[]={
42, 46, 50, 54, 60, 66, 72
};

main.c:

#include "foo.h"
...
fred = Table[4];
...

How about structs?
I do use for example:
file1.c file1.h file2.c file2.h
In file1.c I have
struct my_example_structure {
unsigned char my_char;
unsigned short my_count;
unsigned char my_string[20];
} my_example;
What do I put in file1.h?
I tried
struct my_example_structure my_example;
In file2.h or file2.c I do include file1.h
In file2.c,
example.my_char (or whatever) is not known

How should I do this correctly?

Jack.

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

Hi, Jack--

Quote:

How about structs?

How do you catch a unique rabbit? Unique up on it.
How do you catch a tame rabbit? The tame way.

Let's do structs the tame --err, same-- way.

Now, some "old" code re CV structures may break in 2.x, as the requirement to have the structure template specify the memory area (SRAM, flash, EEPROM) has been removed. [the old way was a pain-in-the-butt for structure assignments across memory areas, requiring a template for each memory area that was prone to error.]

foo.h:

struct my_example_structure {
unsigned char my_char;
unsigned short my_count;
unsigned char my_string[20];
};

extern struct my_example_structure my_example;

foo.c:

struct my_example_structure my_example; 

main.c:

#include "foo.h"
...
fred = my_example.my_count;
...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

theusch wrote:
Hi, Jack--

Quote:

How about structs?

How do you catch a unique rabbit? Unique up on it.
How do you catch a tame rabbit? The tame way.

Let's do structs the tame --err, same-- way.

Now, some "old" code re CV structures may break in 2.x, as the requirement to have the structure template specify the memory area (SRAM, flash, EEPROM) has been removed. [the old way was a pain-in-the-butt for structure assignments across memory areas, requiring a template for each memory area that was prone to error.]

foo.h:

struct my_example_structure {
unsigned char my_char;
unsigned short my_count;
unsigned char my_string[20];
};

extern struct my_example_structure my_example;

foo.c:

struct my_example_structure my_example; 

main.c:

#include "foo.h"
...
fred = my_example.my_count;
...

Thank you very much!

I'll try that.

Jack.

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

That actually, worked!
Thanks again!
Finally, the new cvavr 2 work with my old hobby project.
I think I need to make thing more clean, but it compiles with no errors and the project works.
Jack.