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