0

This is my hello.cpp file:

#include <iostream>
#include "cat.h"

using namespace std;

int main() {
    speak();
    return 0;
}

This is my cat.h file:

#ifndef CAT_H_
#define CAT_H_

void speak(); 

#endif

and this is my cat.cpp file

#include "cat.h"
#include <iostream>

using namespace std;

void speak(){
    cout << "yolo" << endl;
}

Why does it not compile? I keep getting this error:

undefined symbols for architecture x86_64:
  "speak()", referenced from:
      _main in hello-9525f8.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I tried to compile it like this: g++ hello.cpp

Dinu Nicolae
  • 1,019
  • 2
  • 17
  • 42

0 Answers0