When using "extern" in C++, I put "extern int xxx" in the "a.h" and all the other ".cpp" files contain this "a.h". Then, "int xxx = 10" is used in "main.cpp" to define it. However, error "undefined reference to `xxx' " occurs.
SOLUTION: put the definition "int xxx = 10" in the beginning of "main.cpp", following the "#include ..." code, which means out of "int main()", then it works.