I just wanna run a very simple c++ code on my macbook(M1). It shows the error as follows
>> g++ main.cpp -o main
Undefined symbols for architecture arm64:
"sayhi()", referenced from:
_main in main-636bbc.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
There are 3 files:
# main.copp
#include <iostream>
#include "method.h"
using namespace std;
int main(){
sayhi();
return 0;
}
# method.cpp
#include <iostream>
#include "method.h"
using namespace std;
void sayhi(){
//cout << "hi" << endl;
}
# method.h
void sayhi();
Could anyone provide some suggestions?
If I delete the line "sayhi();" in main.cpp
, it works. So, I'm quite sure the problem happens at the line "sayhi();".