I am very new at c++ programming and programming in general. Recently we've been adding header files and other source files (implementation) to our programs in class. I've tried writing the simplest of programs to make sure I understand the basics for including multiple files into one program but they will not compile, giving me linker errors.
namely:
Undefined symbols for architecture x86_64:
"FooBar::printSomething()", referenced from:
_main in main-d52d70.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
When I compile in the terminal with "g++ main.cpp implementation.cpp", everything works just fine.
my code:
main.cpp
#include "header.h"
int main()
{
FooBar object;
object.printSomething();
return 0;
}
header.h
#ifndef _Header_h_
#define _Header_h_
#include <iostream>
using namespace std;
class FooBar{
public:
void printSomething();
private:
string helloWorld;
};
#endif
implementation.cpp
#include "header.h"
void FooBar::printSomething(){
helloWorld = "Hello World!\n";
cout << helloWorld;
}
I love CodeRunner but this is really frustrating me.
Thank you!