另一个:建筑x86_64:的未定义符号
Another one: Undefined symbols for architecture x86_64:
我一直在浏览所有不同的"未定义符号"帖子,但我仍然无法让我的特定情况发挥作用。我最初在编译我的大项目时收到了未定义的错误,但即使我将其本地化到特定类,我仍然会收到错误。我对C++很陌生,我觉得关于编译器和链接器如何在C++中工作有一些更大的概念。我不确定要包含多少代码,但请告诉我我包含的内容是否过多。所以现在的代码:
我的头文件
#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)
感谢您的帮助!!
要么是
编译 Process
的代码时出现问题,你没有包括,要么你没有告诉 g++ 在哪里可以找到要链接到的库。
"未定义的符号"类型错误意味着链接器找不到符号的已编译代码。(在本例中Process::setWT
、Process::setTAT
和Process::print
。你需要告诉 g++ 在哪里可以找到要链接到的库。
http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
代码如何使用 g++ 编译的简要概述是:1) g++
将代码编译为目标文件和/或库,2) ld
(链接器)将目标文件和库链接到可执行文件中。
这是简化的,但重要的是要知道链接器需要知道哪些对象文件和库(编译的代码,但不是可执行文件)链接在一起以创建可执行文件。
相关文章:
- vscode g++链路故障:体系结构x86_64的未定义符号
- 体系结构x86_64的未定义符号:std:terminate(),typeinfo,运算符delete[],运算符new
- C++ 中 dlsym 的未定义符号
- 仅在 MacOS 上析构函数的未定义符号
- OSX clang++:用于 cpp 文件中显式实例化模板的体系结构x86_64的未定义符号
- PCL 出错:体系结构x86_64 @pcl的未定义符号
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 体系结构x86_64的未定义符号:链接器错误
- C++ std::vector<int> 体系结构的未定义符号 x86_64:
- 生成文件:体系结构x86_64的未定义符号
- libc++abi未定义符号:_ZTVN10__cxxabif120__si-class_type_infoE
- Xcode"体系结构x86_64的未定义符号"
- 体系结构x86_64的未定义符号:找不到原因
- SWIG链接器:未定义符号:_ZN2cv8fastFreeEPv(cv::fastFree(void*))
- 如何修复架构x86_64的未定义符号,Boost Asio 1.58
- 在Qt5上去静态库:架构的未定义符号x86_64:
- 体系结构x86_64的未定义符号:c++/ h 文件和 cpp 文件
- 监视 SDK 下的未定义符号"__Unwind_SjLj_Unregister"
- 使用 Boost/Python 的未定义符号 - 复杂
- 建筑x86_64的未定义符号:"vtkDebugLeaksManager::vtkDebugLeaksManager()",引用自: