0

Undefined symbols for architecture x86_64: "Log(char const*)", referenced from: _main in main-cc9ca1.o ld: symbol(s) not found for architecture x86_64

I am just starting to learn cpp.

in main.cpp I have:

#include <iostream>
using namespace std;

void Log(const char* message);


int main() {
    Log("Hello world");
    cin.get();
    
}

in log.cpp I have:

#include <iostream>
 
using namespace std;

void Log(const char* message) {
    cout << message << " hehe" << endl;
}

I can't seem to be able to compile it. I am doing it in visual studio code on Mac.

Y S
  • 9
  • 1
  • 5
    You need to compile and link both files. Most likely you aren't doing that – UnholySheep Mar 16 '22 at 23:26
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Stephen Newell Mar 16 '22 at 23:30
  • The above suspicion can be proved one way or the other by adding the command or the build automation configuration file used to build the program to the question. Right now the best anyone can do is guess, even thought hat guess is probably correct. – user4581301 Mar 16 '22 at 23:30
  • I still get the same message from the visual studio code – Y S Mar 16 '22 at 23:30
  • 1
    [Give this question a read over](https://stackoverflow.com/questions/47665886/vs-code-will-not-build-c-programs-with-multiple-cpp-source-files) and see if it help you sort out the VS Code configuration to ensure log.cpp is being built and linked. – user4581301 Mar 16 '22 at 23:32

0 Answers0