Undefined symbols for architecture x86_64: Index Interface - c++

I am creating an interface called Index that will allow me to Index using either a hash table or a AVL tree. I am getting the following error:
Undefined symbols for architecture x86_64:
"IndexHash::IndexHash(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)", referenced from:
_main in main.o
"IndexHash::IndexHash()", referenced from:
Parser::createIndex() in Parser.o
These are coming from the lines:
Index* mainIn;
// creates a new index pointer
if (indexType_ == 1) {
mainIn = new IndexAVL();
} else if (indexType_ == 2) {
mainIn = new IndexHash();
}
This worked when it was just the AVL tree.
Index.H
#ifndef INDEX_H
#define INDEX_H
#include <iostream>
#include <fstream>
#include <vector>
#include "WordEntry.h"
#include "Document.h"
class Index {
public:
virtual WordEntry* search(WordEntry*&)=0;
virtual void insert(WordEntry*&)=0;
virtual void insert(string)=0;
virtual void printOut(ofstream&)=0;
virtual void createDocument(string, string, string)=0;
virtual int getNumberDocs()=0;
virtual void trim(string&)=0;
private:
};
#endif
IndexHash.h
#ifndef INDEXHASH_H
#define INDEXHASH_H
#include <iostream>
#include <fstream>
#include <vector>
#include "WordEntry.h"
#include "IndexHash.h"
#include "Document.h"
#include <tr1/unordered_map>
class IndexHash : public Index{
public:
IndexHash();
IndexHash(string);
IndexHash(const IndexHash&);
~IndexHash();
virtual WordEntry* search(WordEntry*&);
virtual void insert(WordEntry*&);
virtual void insert(string);
virtual void printOut(ofstream&);
virtual int getNumberDocs();
virtual void trim(string&);
virtual void createDocument(string, string, string);
int searchDocs(string);
Document* binarySearch(vector<Document*>*, int, int, int);
void quickSort(vector<Document*>*, int, int);
private:
tr1::unordered_map< WordEntry*, vector<Document*> >* hashtable_;
vector<Document*>* seenDocs;
};
#endif /* INDEXHASH_H */
IndexHash.cpp
#include "IndexHash.h"
#include "Document.h"
#include <vector>
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <istream>
using namespace std;
IndexHash::IndexHash() {
hashtable_ = new tr1::unordered_map< WordEntry*, vector<Document*> >;
seenDocs = new vector<Document*>;
}
... it defines everything, it is just hard for me to copy and paste it in here and I am assuming the problems is in includes.

Related

Undefined symbols for architecture x86_64 in cpp

I have a programme that I am writing in Qt Creator, and I am having some compilation issues. This is the error it gives:
Undefined symbols for architecture x86_64:
"VehicleSizer::VehicleSizer(double, double, double, double, double, double, double, double, int)", referenced from:
_main in MSSTO_SimulationTester.cpp.o
Reading other questions I thought it would be due to the mismatch between the declared function definitions in the header and the source file, or that the static variables must be initialised, but I don't think that is the case here. Here is my main file:
#include "Vehicle/vehicleSizer.h"
#include "Vehicle/vehicleSizerAbstract.h"
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <string>
#include <boost/bind.hpp>
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
int main( )
{
{
double totalBurnTimeUp = 100.;
double massFlowUpper = 80.;
double chamberPressure = 200000.;
double exitDiameterUp = 1.2;
double oxidizerOverFuel = 3.4;
double upperStageDiameter = 6;
double payloadMass = 1000;
double __landingburn = 1.0;
int __engines = 5;
UpperStage = std::shared_ptr< VehicleSizerAbstract >(
new VehicleSizer(totalBurnTimeUp,
__landingburn,
massFlowUpper,
chamberPressure,
exitDiameterUp,
oxidizerOverFuel,
upperStageDiameter,
payloadMass,
__engines));
std::shared_ptr<VehicleSizerAbstract> Vehicle;
}
return 0;
}
Here is my abstract header file
#ifndef VEHICLESIZERABSTRACT_H
#define VEHICLESIZERABSTRACT_H
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cmath>
class VehicleSizerAbstract
{
public:
// some declared virtual functions that return doubles
virtual ~VehicleSizerAbstract(){}
protected:
// some declared variables
};
#endif // VEHICLESIZERABSTRACT_H
Here is my header file
#ifndef VEHICLESIZER_H
#define VEHICLESIZER_H
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cmath>
#include "vehicleSizerAbstract.h"
class VehicleSizer : public VehicleSizerAbstract
{
public:
VehicleSizer(double m_ascentBurnTime, double m_landingBurnTime,
double m_massFlow, double m_chamberPressure,
double m_exhaustDiameter, double m_mixtureRatio,
double m_vehicleDiameter, double m_payloadMass,
int m_mainEngineAmount);
// some declared functions that return doubles
private:
// some declared void functions
};
#endif // VEHICLESIZER_H
Here is my cpp file:
#include "vehicleSizer.h"
VehicleSizer::VehicleSizer(double m_ascentBurnTime, double m_landingBurnTime,
double m_massFlow, double m_chamberPressure,
double m_exhaustDiameter, double m_mixtureRatio,
double m_vehicleDiameter, double m_payloadMass,
int m_mainEngineAmount)
{
// some functions
}
What am I missing? I have been looking through all of the similar questions and corresponding answers here but nothing seems to apply or to work. Thank you so much!

Referee.cpp:10:18: error: no matching function for call to ‘Human::Human()’ Referee::Referee()

I'm new to c++ and was having problem with doing some inheritance, does any one know why im getting this error? (its the only error I'm getting when compiling).
I compiled with g++ -o. Also I'm so sorry in advance if I'm doing a lot of things wrong here, I'm very new to c++. >_<
Please let me know how I can make my code better or more efficient.
computer.h
#ifndef RPS_H
#define RPS_H
#include <iostream>
#include <string>
#include <stdio.h>
class Computer
{
public:
Computer(std::string);
~Computer();
char charc;
};
#endif
human.h
#ifndef HUMAN_H
#define HUMAN_H
#include <iostream>
#include <string>
#include <stdio.h>
class Human
{
public:
Human(std::string);
~Human();
char charh;
};
#endif
referee.h
#ifndef REFEREE_H
#define REFEREE_H
#include <iostream>
#include <string>
#include <stdio.h>
#include "human.h"
class Referee : public Human{
public:
Referee();
~Referee();
bool Winneris();
};
#endif
Computer.cpp
#include <iostream>
#include <string>
#include <stdio.h>
#include "computer.h"
using namespace std;
Computer::Computer(string char_c)
{
}
Computer::~Computer()
{
}
Human.cpp
#include <iostream>
#include <string>
#include <stdio.h>
#include "human.h"
using namespace std;
Human::Human(string char_h){
char_h=charh;
cout<<"r/p/s?"<<endl;
cin>>charh;
}
Human::~Human()
{
}
Referee.cpp
#include <iostream>
#include <string>
#include <stdio.h>
#include "referee.h"
using namespace std;
Referee::Referee(){
}
bool Referee::Winneris(){
if (charh=='r'){
cout<<"draw"<<endl;
}
else if(charh=='p'){
cout<<"Victory!"<<endl;
}
else if(charh=='s')
{
cout<<"Defeat"<<endl;
}
return 0;
}
Referee::~ReReferee(){
}
main.cpp
#include <iostream>
#include <string>
#include <stdio.h>
#include "human.h"
#include "computer.h"
#include "referee.h"
using namespace std;
string char_h;
string char_c;
// main program
int main()
{
Human *round1h;
round1h = new Human(char_h);
Computer *round1c;
round1c = new Computer(char_c);
Referee *round1r;
round1r = new Referee();
round1r -> Winneris();
}
When you have written the parameterized constructor in respective classes. You have created the class objects, which call the default constructor which takes no parameter.
You have to define the default constructor as well in your respective classes.
Human::Human()
{}
Computer::Computer()
{}
Referee::Referee()
{}
Constructor types

undefined reference to vtable when using interface

I've looked around, and I can't quite figure out where I'm going wrong, as I seem to be following the correct convention when using interfaces, but perhaps I'm overlooking something. The exact error I'm getting is:
undefined reference to `vtable for Icommand'
I've only just begun to seperate my classes and class declarations into separate header files, so perhaps I'm missing a preprocessor directive somewhere.
main.cpp:
#include <iostream>
#include <string>
#include <cstdlib>
#include "Icommand.h"
#include "Command.h"
using namespace std;
void pause();
int main(){
Icommand *run = new Command("TEST");
cout << run->getCommand() << endl;
delete run;
pause();
}
void pause(){
cin.clear();
cin.ignore(cin.rdbuf()->in_avail());
cin.get();
}
Icommand.h:
#ifndef ICOMMAND_H
#define ICOMMAND_H
#include <string>
#include <vector>
class Icommand
{
private:
public:
Icommand(){}
virtual ~Icommand(){}
virtual bool run(std::string object1) = 0;
virtual bool run(std::string object1, std::string object2) = 0;
virtual std::string getCommand() const;
};
#endif // ICOMMAND_H
Command.h:
#ifndef COMMAND_H
#define COMMAND_H
#include <string>
#include <vector>
#include "Icommand.h"
class Command : public Icommand {
private:
std::string command;
std::vector<std::string> synonymns;
Command(); // private so class much be instantiated with a command
public:
Command(std::string command) : command(command){}
~Command(){}
bool run(std::string object1);
bool run(std::string object1, std::string object2);
std::string getCommand() const;
};
#endif // COMMAND_H
Command.cpp:
#include <string>
#include <vector>
#include "Command.h"
bool Command::run(std::string object1){
return false;
}
bool Command::run(std::string object1, std::string object2){
return false;
}
std::string Command::getCommand() const {return command;}
In Icommand.h, replace
virtual std::string getCommand() const;
with
virtual std::string getCommand() const = 0;
to make it pure virtual. Then the compiler can generate a vtable for Icommand. Alternatively, implement Icommand::getCommand.

Usage of vector + inheritance

What I'd like to do, is add an object to my obiektGeometryczny vector, which would be a Manipulator or kwadrat type.
I want "przeszkoda" to be an obstacle of Manipulator or kwadrat (square in polish) type.
I've tried to use:
obiektGeometryczny.push_back(new Manipulator());
but it returns:
src/scena.cpp:71:36: error: expected type-specifier before ‘*’ token
obiektGeometryczny.push_back(new *Manipulator);
Below is the code:
scena.hh
#ifndef SCENA_HH
#define SCENA_HH
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <unistd.h>
#include <vector>
#include "manipulator.hh"
#include "kwadrat.hh"
#include "przeszkoda.h"
class scena{
vector<przeszkoda*> obiektGeometryczny;
public:
scena(int argc, char *argv[]);
};
#endif
przeszkoda.hh
#ifndef PRZESZKODA_HH
#define PRZESZKODA_HH
class przeszkoda{
virtual void czyPrzeciecie() {;};
};
#endif
manipulator.hh
#ifndef MANIPULATOR_HH
#define MANIPULATOR_HH
#include "przeszkoda.hh"
class Manipulator : public przeszkoda
{
void czyPrzeciecie();
};
#endif
kwadrat.hh
#ifndef KWADRAT_HH
#define KWADRAT_HH
#include "przeszkoda.hh"
class kwadrat : public przeszkoda
{
void czyPrzeciecie();
};
#endif
It is not minimal example - there is something more you didn't show us. Code you posted is ok - try to simplify your case, because something like this works correctly:
#include <vector>
using namespace std;
class A {
int x;
};
int main(void) {
vector<A*> v;
v.push_back(new A());
return 0;
}

Getting symbols error: 'ld: symbol(s) not found'

I'm trying to execute this code, but I'm getting the symbol error of the title:
configfile.cpp:
#include "configFile.h"
#include <iostream>
#include <sstream>
#include <fstream>
#include <cstdlib>
#include <stdexcept>
#include <map>
configFile* configFile::getInstance(){
pinstance = new configFile();
return pinstance;
}
configFile::configFile(){
filename = "/Users/myfolder/NetBeansProjects/Oier_2/config.cfg";
}
void configFile::setConfigFileName(std::string s){
filename = s;
}
float* getConfiguration(std::string type, int size) {
std::string data[size];
std::string line;
std::ifstream myfile("/Users/myfolder/NetBeansProjects/Oier_2/config.cfg");
while (std::getline(myfile, line)) {
std::istringstream is_line(line);
std::string key;
if (std::getline(is_line, key, '=')) {
if(key.compare(type) == 0){
for(int i=0; i<size;i++){
std::getline(is_line,data[i],',');
}
}
}
}
float *fdata;
for(int i=0;i<size;i++){
fdata[i] = (float)atof(data[i].c_str());
}
return fdata;
}
And configFile.h:
#include <string>
#ifndef CONFIGFILE_H
#define CONFIGFILE_H
class configFile {
private:
static configFile* pinstance;
static std::string filename;
public:
static configFile* getInstance();
void setConfigFileName(std::string s);
float* getConfiguration(std::string type, int size);
protected:
configFile();
configFile(const configFile& orig);
};
#endif /* CONFIGFILE_H */
The symbols error I'm having:
Undefined symbols: "configFile::filename", referenced from:
configFile::configFile()in configFile.o
configFile::configFile()in configFile.o
configFile::setConfigFileName(std::basic_string, std::allocator >)in configFile.o
"configFile::pinstance", referenced from:
configFile::getInstance() in configFile.o
configFile::getInstance() in configFile.o "configFile::getConfiguration(std::basic_string
std::char_traits, std::allocator >, int)", referenced
from:
_main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
If it's necessary: main.cpp:
#include <cstdlib>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <algorithm>
#include "configFile.h"
using namespace std;
int main(int argc, char** argv) {
configFile* cfg = configFile::getInstance();
string type = "tiempo";
float* tiem = cfg->getConfiguration(type,3);
for(int i=0; i< 3;i++){
printf( " %f ", tiem[i]);
}
}
I'm running a MaxOSX 10.6.8. Thanks in adavance
These two areas are the issue:
configFile::configFile(){
filename = "/Users/myfolder/NetBeansProjects/Oier_2/config.cfg";
}
void configFile::setConfigFileName(std::string s){
filename = s;
}
You've declared filename as a static data member, so its name must always be configFile::filename. If you meant to use a data member, you can simply remove the static definition.
The difference between static and non-static data members is that with static, only one variable exists, whereas with a non-static data member there is an instance of this variable per-class. So in this case, the consequence is that with static, each instance of configFile would reference the same file path, whereas removing static would make each configFile own its own filename and so have its own file path.