творю объект файла журнала на дне является .h и .ccC++ LogFile Объект ошибки компиляции
Беллоу ошибка я получаю, пожалуйста, помогите
неопределенные символы для архитектуры x86_64:
«LogFile :: log (std :: __ 1 :: basic_string, std :: __ 1 :: allocator>)», ссылка от: TextDisplay :: notify (int, int, Cell :: CellType) в textdisplay.o Этаж :: loadFloor (std :: __ 1 :: basic_string, std :: __ 1 :: allocator>, Player *) в floor.o Этаж :: isStairwaySet() в floor.o Этаж :: getCellAtCoord (int, int) в floor.o Этаж :: getPossibleSpots (Occupant *, int, int) в floor.o Этаж :: getNearbyPlayer (int, int) in floor.o Характер :: dealDamage (int) в character.o ... "LogFile :: log (char const *)", ссылка от: CC3K :: cleanUp() в cc3k.o CC3K :: startGame (Occupant :: SpecificType, std :: __ 1 :: basic_string, std :: __ 1 :: allocator>) в cc3k.o CC3K :: step() в cc3k.o CC3K :: playerMove (CC3K: : Command, CC3K :: Direction) в cc3k.o Этаж :: loadFloor (std :: __ 1 :: basic_string, std :: __ 1 :: allocator>, Player *) в floor.o Этаж :: notifyStairwayBeingSet (int, int) в floor.o Cell :: removeDeadOccupant() in cell.o ... "LogFile :: dlog (std :: __ 1 :: basic_string, std :: __ 1 :: allocator >), ссылается на: от: Торговец :: attackStep() в merchant.o "LogFile :: dlog (char const *)", ссылка от: Персонаж :: атака (персонаж &) в character.o Торговец: : attackStep() в merchant.o «LogFile :: getI()», на который ссылаются: CC3K :: cleanUp() в cc3k.o CC3K :: startGame (Occupant :: SpecificType, std :: __ 1 :: basic_string, std :: __ 1 :: allocator>) в cc3k.o CC3K :: step() в cc3k.o CC3K :: playerMove (CC3K :: Command, CC3K :: Direction) в cc3k.o TextDisplay :: notify (int, int, Cell :: CellType) в textdisplay.o Этаж :: loadFloor (std :: __ 1 :: basic_string, std :: __ 1 :: allocator>, Player *) в floor.o Этаж :: notifyStairwayBeingSet (интермедиат, целое) в floor.o ... л.д.: символ (ы) не найдено для архитектуры x86_64
ниже является несколько строк кода ошибки говорит о
LogFile::getI()->log("Error textdisplay.cc 77: Weird cellType given: " + to_string(cellType));
LogFile::getI()->log("Error floor.cc isStairwaySet() 141: Weird values for stairwayRow: " + to_string(stairwayRow) + " stairwayCol: " + to_string(stairwayCol));
.h
#ifndef __LOGFILE_H__
#define __LOGFILE_H__
#include <string>
class LogFile
{
static LogFile *singleton;
LogFile(std::string fileName);
~LogFile();
int logNum;
std::string fileName;
static void cleanUp();
public:
enum Error {};
//must be called before use, fileName to log too
static LogFile *initInstance(std::string fileName);
static LogFile *getI();
void log(std::string error);
void log(const char *error);
void dlog(std::string error);
void dlog(const char *error);
bool hasLoged();
int getNumLogs();
};
#include "logfile.h"
.cc
#include "logfile.h"
#include <ofstream>
#include <cstdlib>
using namespace std;
static LogFile *LogFile::singleton = NULL;
void LogFile::cleanUp()
{
delete singleton;
}
LogFile::LogFile(std::string fileName): logNum(0), fileName(fileName){}
LogFile::~LogFile(){}
//must be called before use, fileName to log too
LogFile *LogFile::initInstance(std::string fileName) //static
{
if(singleton)
{
singleton->log("Error: logfile.cc initInstance() 19: Calling this function more than once is wrong implementation");
return singleton;
}else
{
singleton = new LogFile(fileName);
#ifdef REPRAND
singleton->log("#define REPRAND");
#endif
#define DEBUG
singleton->log("#define DEBUG");
#endif
atexit(cleanUp)
return singleton;
}
}
LogFile *LogFile::getI() //static
{
if(!singleton)
{
LogFile::getI()->log("Error: logfile.cc getInstance() 32: Calling getInstance() without having first called initInstance()");
}else
{
return singleton;
}
}
void LogFile::log(std::string error)
{
ofstream ofs;
ofs.open(fileName.c_str(), ofstream::out | ofstream::app);
ofs << error << endl;
if(!ofs.good)
LogFile::getI()->log("Error writeToFile() 47: output file stream is not good");
logNum ++;
}
void LogFile::log(char *error)
{
log(string(error));
}
void LogFile::dlog(std::string error)
{
#ifdef DEBUG
log(error);
#endif
}
void LogFile::dlog(char *error)
{
dlog(string(error));
}
bool LogFile::hasLoged()
{
return (logNum > 0);
}
int LogFile::getNumLogs()
{
return logNum;
}
Вам нужно вернуться и начать с чтения на С ++. Затем вы можете заметить, что определения функций членов должны быть правильно определены, например, например. 'LogFile :: log', а не только' log'. –
Как вы можете скомпилировать исходный код? Какой идеал вы используете? Или вы пишете собственный Makefile? Неопределенный символ - это ошибки компоновщика. – nio
Этот вопрос выглядит не по теме, потому что он забывает добавить имя файла в файл make –