I'm learning C++ language on VSCode with Mac, and when I build my project, it throw an error as following:
Undefined symbols for architecture x86_64:
"sum(int, int)", referenced from:
_main in hello-7c63b5.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The project has three files, as follows:
hello.cpp
#include<iostream>
#include "sum.h"
using namespace std;
int main(){
cout << "hello" << endl;
sum(1, 1);
return 0;
}
sum.h
#include <iostream>
using namespace std;
void sum(int a, int b);
sum.cpp
#include "sum.h"
void sum(int a, int b)
{
cout << a+b << endl;
}
Does any else has idea to solve it? Thanks very much!