gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Undefined reference to data

#146187 - JScott - Fri Nov 30, 2007 6:40 am

I'm working on a GBA project using devkitPro and I'm getting linker errors.

My data isn't getting linked in at all. I can throw it all into the header, but I'd rather not. I have multiple sets of .h and .cpp files, some with extern data, but the only ones that get lost in the shuffle are the tile and palette data files.

Any information would be helpful.

#146189 - gmiller - Fri Nov 30, 2007 7:13 am

If you are using C++ and the data is declared "const" then you need to make sure you also declare it "external" in the same file. The behavior of C++ in this case in contrary to the way C would handle it but it is in the rules.

I got burned by this. I found out by looking at the generated assembly which had nothing in it ... "-save-temps"

#146190 - JScott - Fri Nov 30, 2007 8:22 am

Well everything works now. Thanks for the info I never would have tried that.

I can't use C files for some reason the linker complains about all kinds of stuff so everything is c++.

#146204 - tepples - Fri Nov 30, 2007 1:42 pm

JScott wrote:
I can't use C files for some reason the linker complains about all kinds of stuff

Please paste what the linker complains about so that I can help you find out whether or not it's just an extern "C" mismatch.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#146450 - JScott - Tue Dec 04, 2007 12:07 pm

I think it's just my make file. If I use the extension .c I get link errors but using .cpp there's no problem. I'm not concerned about it. It compiles and runs fine.

Maybe after I finish my assignment I'll look into it more.