Search the web
Sign In
New User? Sign Up
gbadev
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Click here for the latest updates on Groups Message search

Messages

  Messages Help
Advanced
Strange const problem   Topic List   < Prev Topic  |  Next Topic >
Reply < Prev Message  | 
I'm having a strange problem using constant variables that I can't figure
out. It seems like the constants don't get linked at all. In a very simple
compiler test program I made, have 3 files, main.cpp, bg.cpp and bg.h. Here
are the contents of those files:

BG.CPP
[
const int myArray[4] = {1,2,3,4};
]

BG.H
[
extern const int myArray[4];
]

MAIN.CPP
[
#include <stdio.h>
#include "bg.h"

int main()
{
printf("%i", myArray[2]);
}

]

When I try to link, these errors come up:
main.o(.text+0x3c): undefined reference to `myArray'
main.o(.rodata+0xc): undefined reference to `myArray'

bg.cpp compiles perfect. If I take away the 'const', then everything works
fine. Also, if I change the files names to .c and compile in c mode, it
works. My link flags are: -g -o $(OFILES) -nostartfiles

Thanks for any help or suggestions.

Matt






Wed Sep 25, 2002 2:37 pm

wbottle2
Offline Offline
Send Email Send Email

< Prev Message  | 
Expand Messages Author Sort by Date

I'm having a strange problem using constant variables that I can't figure out. It seems like the constants don't get linked at all. In a very simple compiler...
Matthew Rogers
wbottle2
Offline Send Email
Sep 25, 2002
3:13 pm

It looks like a bug in compiler... But if it works in C mode - compile your array in C mode! For arrays it doesnt matter if its C or CPP. ave, porneL -- 1200...
porneL
pornelkurna
Offline Send Email
Sep 25, 2002
3:38 pm

Wiki? What the heck is that? A Wiki Wiki Web is an Internet site that allows the users to create the content. Its really easy and fun to use. I have started a...
Jason Wilkins
fenix@...
Send Email
Sep 25, 2002
10:07 pm

this may be wrong, but I though C++ had some rules about const having static linkage I believe it's to do with C++ const meaning compile time constant rather...
Mike Wynn
mike.wynn@...
Send Email
Sep 25, 2002
5:33 pm

Hiya, MR> bg.cpp compiles perfect. If I take away the 'const', then everything works MR> fine. Also, if I change the files names to .c and compile in c mode,...
Neil Griffiths
godaldur
Offline Send Email
Sep 25, 2002
5:33 pm

From: "Matthew Rogers" <presbywf@...> ... figure ... very simple [...] you need to include bg.h in bg.cpp. everything has static linkage in c++ by...
Matthew Conte
whatwouldbig...
Offline Send Email
Sep 26, 2002
11:14 am

I believe I just experienced the same problem you're having. Using devkit 2.9X, Jeff's ctr0 and lnkscript, here is what worked for me: in BG.h class BG{ ... ...
Johnny_north
j_north2002
Offline Send Email
Sep 26, 2002
2:08 pm
Advanced

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help