B
Ben Bacarisse
I have an array (much messier than this cut-down example) that I want to
hive off into another source file, but the two compiled files won't
link:
m.cc:
extern int *const table[];
int main()
{
return *table[0];
}
t.cc:
static int t1[] = { 1, 2, 3 };
static int t2[] = { 2, 3, 4 };
int *const table[] = { t1, t2 };
g++ says:
$ g++ -std=c++98 -pedantic m.cc t.cc
/tmp/ccniFOW7.o: In function `main':
m.cc.text+0x7): undefined reference to `ns::table'
collect2: ld returned 1 exit status
It works as one file where the content of t.cc follows main in m.cc. It
also work if I simply remove the "const" in t.cc.
What's going on?
hive off into another source file, but the two compiled files won't
link:
m.cc:
extern int *const table[];
int main()
{
return *table[0];
}
t.cc:
static int t1[] = { 1, 2, 3 };
static int t2[] = { 2, 3, 4 };
int *const table[] = { t1, t2 };
g++ says:
$ g++ -std=c++98 -pedantic m.cc t.cc
/tmp/ccniFOW7.o: In function `main':
m.cc.text+0x7): undefined reference to `ns::table'
collect2: ld returned 1 exit status
It works as one file where the content of t.cc follows main in m.cc. It
also work if I simply remove the "const" in t.cc.
What's going on?