この簡単な例があり、コンパイルできません。
3 つのファイル: 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;
}
コンパイルしようとすると、次の 3 つのエラーが発生します: LNK2001: extern "int foo".. LNK2019: extern "int foo".. LNK1120:
私は何を間違っていますか?助けてくれてありがとう