我有这个简单的例子,但我无法编译:
三个文件:my.h、my.cpp和use.cpp:
//my.h
extern int foo;
void print_foo();
void print(int);
//my.cpp
#include "my.h"
#include "../../stb_lib_facilities.h" //inlcudes cout, cin, etc
void print_foo(){
cout << foo << endl;
}
void print(int i){
cout << i << endl;
}
//use.cpp
#include <iostream>
#include "my.h"
int main(){
foo = 7;
print_foo();
print(99);
return 0;
}
当我尝试编译它时,我收到三个错误: LNK2001: extern "int foo".. LNK2019: extern "int foo".. LNK1120:
我究竟做错了什么?谢谢你的帮助