0

I am trying to get the grasp on how to use header files in c++ but I keep getting this error:

Undefined symbols for architecture x86_64:
  "myclass::myclass()", referenced from:
      _main in main-06f616.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This is the code that i am running. ( it is a very simple code, because again, I am trying to understand this.)

main.cpp:

#include <iostream>
#include "func.hpp"


using namespace std;

int main(){
    myclass classone;

    return 0;
}

func.hpp:

#ifndef func_H
#define func_H

class myclass {
    public:
        myclass();
};

#endif

func.cpp:

#include "func.hpp"
#include <iostream>

using namespace std;

myclass::myclass(){
    cout << "I am a banana" << endl;
}
drescherjm
  • 10,365
  • 5
  • 44
  • 64
  • How are you compiling your code? – MikeCAT Oct 23 '20 at 18:04
  • Are you using Visual Studio Code? If so you need to modify `tasks.json` to allow for building of more than 1 source file. The default configuration supports only a single .cpp file. – drescherjm Oct 23 '20 at 18:07
  • The problem appears that `func.cpp` is not being built into your executable. – drescherjm Oct 23 '20 at 18:08
  • How do i fix this? sorry I am new and not sure what the ```tasks.json``` is. I am using Visual Studio Code, yes. @MikeCAT @drescherjm – user13731744 Oct 23 '20 at 18:16
  • The documentation tells you how to fix it here: [https://code.visualstudio.com/docs/cpp/config-mingw#_modifying-tasksjson](https://code.visualstudio.com/docs/cpp/config-mingw#_modifying-tasksjson) – drescherjm Oct 23 '20 at 18:20

0 Answers0