I have a question on how to compile a C++ program in Terminal Mac. My program has a header file and a main file. I know that I can't compile both the header file and the main file. and just to compile the main file. I also know that I need to create a name for storing the compiled file. Here is my compile command that I used g++ -o execute1 main.cpp
and I get this:
Undefined symbols for architecture x86_64:
"add(int, int)", referenced from:
_main in main-f2nZvj.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
How can I fix this? Any help will be greatly appreciated. If it helps, below is my code for the two files:
add.h:
int add(int x, int y);
main.cpp:
#include <iostream>
#include "add.h"
int main(){
using namespace std;
cout << "The sum of 9 and 9 is " << add(9, 9) << endl;
return 0;
}