Я просматривал все разные сообщения «Неопределенный символ», но я до сих пор не могу заставить свою конкретную ситуацию работать. Первоначально я получил неопределенную ошибку при компиляции моего большего проекта, но даже когда я локализую его только для определенного класса, я все равно получаю ошибки. Я довольно новичок в C++, я чувствую, что существует еще одна концепция о том, как компилятор и компоновщики работают на C++. Я не был уверен, сколько из моего кода включить, но дайте мне знать, было ли то, что я включил, было чрезмерным. Так что теперь для кода:Другой: Неопределенные символы для архитектуры x86_64:
мой файл заголовка
#ifndef FCFS_H
#define FCFS_H
#include <vector>
#include <fstream>
#include <iostream>
#include <Process.h>
using namespace std;
class FCFS{
public:
/* Simple Constructor */
FCFS(){
totWaitTime = 0;
totTurnAround = 0;
timeElapsed = 0;
vectorSize = 0;
}
/* Simple Accessors */
inline int returnTotWT() const {return totWaitTime;}
inline int returnTotTAT() const {return totTurnAround;}
inline int returnTime() const {return timeElapsed;}
inline int returnVecSize() const {return vectorSize;}
/* Mutators */
void buildMatrix(ifstream& myinfile);
Process buildProcess(string line);
vector<string>parser (const string& s, const string& w);
bool runSchedule(string myinfile, string myoutfile);
private:
int totWaitTime;
int totTurnAround;
int timeElapsed;
int vectorSize;
vector <Process> arrivedProc;
};
#endif // FCFS_H_INCLUDE
Мой .cpp файл:
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <stdlib.h>
#include <sstream>
#include <Process.h>
#include "FCFS.h"
using namespace std;
void FCFS::buildMatrix(ifstream& myinfile){
string line;
while(getline(myinfile, line)){
Process newProc = buildProcess(line);
arrivedProc.push_back(newProc);
}
sort(arrivedProc.begin(), arrivedProc.end(), Process::compareAT);
vectorSize = arrivedProc.size();
}
vector<string> FCFS::parser (const string& s, const string& w){
string temp{s};
for (char& ch : temp){
for (char white : w){
if (ch == white) ch = ' ';
}
}
vector <string> substrings;
stringstream ss;
ss << temp;
for (string buffer; ss >> buffer;){
substrings.push_back(buffer);
}
return substrings;
}
Process FCFS::buildProcess(string line){
vector<string> procEl = parser(line, ",-");
Process newProc(stoi(procEl[0]), stoi(procEl[1]),
stoi(procEl[2]), stoi(procEl[3]), stoi(procEl[4]), stoi(procEl[5]));
return newProc;
}
bool FCFS::runSchedule(string myin, string myout){
...just implempentation that I don't think is the problem...
}
int main(){
FCFS sched;
string in = "Sample_Input1.txt";
string out = "output.txt";
sched.runSchedule(in, out);
}
моя ошибка:
Ethans-MacBook-Pro:HW4 lozae$ g++ -g -Wall -std=c++11 -I. FCFS.cpp
Undefined symbols for architecture x86_64:
"Process::setWT(double)", referenced from:
FCFS::runSchedule(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in FCFS-53eb8f.o
"Process::setTAT(double)", referenced from:
FCFS::runSchedule(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in FCFS-53eb8f.o
"Process::print(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const", referenced from:
FCFS::runSchedule(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in FCFS-53eb8f.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Спасибо за помощь !!
Какая у вас линия командной строки? –
Что такое 'Процесс'? Если это то, что вы написали, отметьте опечатку. Если это внешняя библиотека, связывайте необходимые вещи. – MikeCAT
«... просто проблема, о которой я не думаю, это проблема ...» И это именно то, где проблема. Отредактируйте сообщение и предоставите [mcve]. Как вы думаете, о чем говорят «ссылки из: FCFS :: runSchedule»? Компилятор сообщает вам, где проблема, и почему-то вы решили, что это не проблема. Странный. –