|
比如我在 extern.cpp中只有下面一句(我就是必须放在cpp文件里面,请不要让我改为extern.h)
int x = 10;
在main.cpp中
extern int x;
然后使用了
cout << x <<endl;
在g++中就是编译不过,提示未定义x,为什么呢?下面是makefile
main: main.cpp extern.o
g++ main.cpp extern.o -o main
extern.o: extern.cpp
g++ -c extern.cpp
还想问一句的是,gcc不能编译cpp程序吗?比如我在以上的makefile里面把g++改为gcc,什么cout,<<等等通通不认识了。 |
|