Question

External variables are not listed by "nm" command because they have been declared as extern so memory for them will not be allocated in this program. Is there any other way to list extern variables? Where stored information about external variables declaration?

os windows 7 compiler mingw or vs2010

Was it helpful?

Solution

They will be there, marked U for undefined.

extern int foo;
int bar() {
  return foo++;
}

Gives:

g++ -c test.cc
nm test.o
00000000 T _Z3barv
         U foo

Note that bar is needed for this example to work. If the variable is unused no reference will be generated in the output.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top