Newbie developer here. I was following this YouTube tutorial by The Cherno from 2017 and I don't know if anything has changed in the functioning of c++ since then, but the code he shows working in the video at the minute 3:55 seems to result in an error for me.
The tutorial is about learning how header files work, but he first makes an example of linking 2 .cpp files, here is the first one:
#include <iostream>
void Log(const char* message){
std::cout<<message<<std::endl;
}
int main(){
Log("Hello World!");
std::cin.get();
}
Here is the second one:
void Log(const char* message);
void InitLog(){
Log("Initializing Log");
}
And here's my error:
Lavoro@iMacdiFrancesco untitled folder % cd "/Users/programmer/Desktop/untitled folder/" && g++ Log.cpp -o Log && "/Users/programmer/Desktop/untitled folder/"Log
Undefined symbols for architecture x86_64:
"Log(char const*)", referenced from:
InitLog() in Log-07d6ab.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Lavoro@iMacdiFrancesco untitled folder %
And a different version of the error I got from trying to put the files together in a folder before executing them:
Lavoro@iMacdiFrancesco untitled folder % cd "/Users/programmer/Desktop/untitled folder/" && g++ Log.cpp -o Log && "/Users/programmer/Desktop/untitled folder/"Log
Undefined symbols for architecture x86_64:
"Log(char const*)", referenced from:
InitLog() in Log-1d2bd8.o
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Lavoro@iMacdiFrancesco untitled folder %
I also tried doing what he does at the minute 7:00, that is using a header file, but that results in the error below, so I guess there's a problem in my setup rather than in my actual code:
Lavoro@iMacdiFrancesco untitled folder % cd "/Users/programmer/Desktop/untitled folder/" && g++ Main.cpp -o Main && "/Users/programmer/Desktop/untitled folder/"Main
Undefined symbols for architecture x86_64:
"Log(char const*)", referenced from:
_main in Main-86283c.o
"InitLog()", referenced from:
_main in Main-86283c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Lavoro@iMacdiFrancesco untitled folder %
I double checked the code and it should be identical to his, also, for context, I'm working on a Mac with Catilina and I'm using Visual Studio Code. Thanks to whatever hero decides to undertake my monstrous code ;)