. Advertisement .
..3..
. Advertisement .
..4..
I am new to programs and searching the undefined symbols for architecture x86_64: to understand it better. It seems it doesn’t work as expected when I used some suggestions before. This is the command line I use:
#include "Main.h"
using namespace std;
static const string TAG = "Main: ";
int main(int argc, char *argv[])
{
string inStreamName;
string logStreamName;
string outStreamName;
ofstream outStream;
string timeCallOutput;
Scanner inStream;
Similarity similarity;
///////////////////////////////////////////////////////////////
// Boilerplate for naming files and opening files
Utils::CheckArgs(3, argc, argv, "infilename outfilename logfilename");
outStreamName = static_cast<string>(argv[2]);
logStreamName = static_cast<string>(argv[3]);
Utils::FileOpen(outStream, outStreamName);
Utils::LogFileOpen(logStreamName);
timeCallOutput = Utils::timecall("beginning");
Utils::logStream << timeCallOutput << endl;
Utils::logStream << TAG << "Beginning execution" << endl;
Utils::logStream << TAG << "outfile '" << outStreamName << "'" << endl;
Utils::logStream << TAG << "logfile '" << logStreamName << "'" << endl;
Utils::logStream.flush();
///////////////////////////////////////////////////////////////
// What follows here is the real work of this code.
// read the entire input file and echo it back
// compute the two similarity coefficients
inStreamName = static_cast<string>(argv[1]);
inStream.openFile(inStreamName);
Utils::logStream << TAG << "infile '" << inStreamName << "'" << endl;
Utils::logStream.flush();
similarity.readData(inStream);
outStream << TAG << "Data Begin\n" << similarity.toString() << endl;
outStream << TAG << "Data End\n" << endl;
outStream.flush();
inStream.close();
outStream << TAG << "Begin similarity computation" << endl;
outStream << TAG << "Maximum Jaccard similarity:\n" <<
similarity.maxJaccard() << endl;
outStream << TAG << "Maximum cosine similarity:\n" <<
similarity.maxCosine() << endl;
outStream << TAG << "End similarity computation" << endl;
outStream.flush();
///////////////////////////////////////////////////////////////
// Boilerplate for terminating gracefully
Utils::logStream << TAG << "Ending execution" << endl;
timeCallOutput = Utils::timecall("ending");
Utils::logStream << timeCallOutput << endl;
Utils::logStream.flush();
outStream.flush();
Utils::FileClose(outStream);
Utils::FileClose(Utils::logStream);
return 0;
}
#ifndef MAIN_H
#define MAIN_H
#include "../../Utilities/Utils.h"
#include "../../Utilities/Scanner.h"
#include "Similarity.h"
class Main
{
public:
int main();
virtual ~Main();
private:
};
#endif // MAIN_H
#include "Similarity.h"
using namespace std;
void readData(Scanner& inStream){
}
string maxCosine(){
return "cosine";
}
string maxJaccard(){
return "jaccard";
}
string toString(){
return "toString";
}
#ifndef SIMILARITY_H
#define SIMILARITY_H
#include "../../Utilities/Scanner.h"
class Similarity
{
public:
Similarity();
virtual ~Similarity();
void readData(Scanner& inStream);
string maxCosine();
string maxJaccard();
string toString();
private:
};
#endif
The error I’m getting is below:
g++ -O3 -Wall -o Similarity.o -c Similarity.cpp
g++ -O3 -Wall -o Aprog Main.o Similarity.o Scanner.o ScanLine.o Utils.o
Undefined symbols for architecture x86_64:
"Similarity::maxJaccard()", referenced from:
_main in Main.o
"Similarity::readData(Scanner&)", referenced from:
_main in Main.o
"Similarity::toString()", referenced from:
_main in Main.o
"Similarity::maxCosine()", referenced from:
_main in Main.o
"Similarity::Similarity()", referenced from:
_main in Main.o
"Similarity::~Similarity()", referenced from:
_main in Main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [Aprog] Error 1
Please give me the solution for this issue.
The error figures out that some symbols are missing (i.e.: you’re missing Similarity::Similarity() or Similarity::~Similarity()) Another thing is you’ve defined the function of the class Similarity incorrectly. For information, a class function should be defined as follow:
and not just
You need to review and update your Similarity.h file…