First time using stack overflow. I am attempting to practice Object oriented abstraction and interfaces. I have been unable to get the program to compile, my program is as below.
main.cpp
#include "Spells.h"
#include <iostream>
int main()
{
spell MagicalSpell;
std::cout << "Hello World!\n";
}
Spells.h
#pragma once
class spell {
private:
int EnergyCost;
public:
spell();
~spell();
void SpellEffect();
};
Spell.cpp
#include "Spells.h"
#include <iostream>
spell::spell() {
EnergyCost = 0;
}
spell::~spell() {
}
void spell::SpellEffect(){
std::cout << "woosh" << std::endl;
}
Every time I attempt to compile main.cpp I get:
g++ main.cpp -lcrypt -lcs50 -lm -o main
/tmp/ccnXk1TN.o: In function `main':
main.cpp:(.text+0x20): undefined reference to `spell::spell()'
main.cpp:(.text+0x3f): undefined reference to `spell::~spell()'
main.cpp:(.text+0x64): undefined reference to `spell::~spell()'
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'main' failed
make: *** [main] Error 1
The following link seems to describe most of the issue. https://askubuntu.com/questions/902857/error-tmp-ccob6cit-o-in-function-main-example-c-text0x4a That person appears to be using a standard library, I think I am just attempting to use individual files that are in the same directory.
I have used multiple files together before from classwork and have not run into this problem. I can still get those files to compile and execute. Did I make a mistake in having the files include each other? Am I supposed to use a different form of a gcc compile command?