Xcode错误,有两个重复的符号



我仍然在修改我的程序,但是我在试图构建时收到的唯一问题是架构x84_64的2个重复符号。我过去没有遇到过这个问题,我在Mac OSX monterey上运行xcode 14.0.1。

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <algorithm>
#include <sstream>
#include "Linked.hpp"
using namespace std;
time_t t = time(0);
tm* now = localtime(&t);
int main(){

LinkedList l;
Node* head = nullptr;
string line;
unsigned int sys_time = 0;

fstream  myfile ("myfile.txt");
if (myfile.is_open()){
cout << "ready to proceed..." << endl;
}

ofstream outputFile ("output.txt");
if (outputFile.is_open()){
cout << "ready to proceed.." << endl;
}
outputFile << "Job_ID " << std::setfill('0') << std::setw(4) << "Priority_Value  " << std::setfill('0') << std::setw(4) << "Arrival_Time" << std::setfill('0') << std::setw(4) << "  Processing_Time" << endl;

while(!myfile.eof()){
std::replace(line.begin(), line.end(), ',', ' ');

stringstream ss(line);

getline(myfile, line);
string date;
int job_ID;
int priority_value;
int arrival_time;
int processing_time;
ss >> job_ID;
ss >> priority_value;
ss >> arrival_time;
ss >> processing_time;
l.enqueue(&head,job_ID, priority_value,arrival_time,processing_time);
}




return 0;
}

#ifndef Linked_hpp
#define Linked_hpp
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <algorithm>
#include <sstream>
using namespace std;
class Node {
public:
Node *next;
int jobID;
int priority_num;
int arrival_time;
int priority_value;
int wait_time;
Node(int jd, int pv, int at, int wt);

};
class LinkedList{

public:
Node *head;
static Node* firstNode(int jd, int pv, int at, int wt);
static int peek(Node** head);
static void enqueue(Node **head,int jd, int pv, int at, int wt);
static void dequeue(Node **head);
static int getLength(Node* head);
static bool isEmpty(Node* head);
static void display(Node* head);

LinkedList();
};

#endif /* LinkedList_hpp */
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <algorithm>
#include <sstream>
#include "Linked.hpp"
time_t t = time(0);
tm* now = localtime(&t);
using namespace std;
Node::Node(int jd, int pv, int at, int wt){
jobID = jd;
priority_value = pv;
arrival_time = at;
wait_time = wt;
next = nullptr;
}
Node* LinkedList::firstNode(int jd, int pv, int at, int wt){
Node *newNode = new Node(jd, pv, at, wt);
newNode->jobID = jd;
newNode->priority_value = pv;
newNode->arrival_time = at;
newNode->wait_time = wt;
return newNode;
}
LinkedList::LinkedList(){
head = NULL;
}
int LinkedList::peek(Node** head){
return (*head)->jobID;
}
void LinkedList::dequeue(Node** head){
Node* newNode = *head;
(*head) = (*head)->next;
free(newNode);
}
void LinkedList::enqueue(Node **head,int jd, int pv, int at, int wt){
Node* startNode = (*head);
Node* tempNode = firstNode(jd, pv, at, wt);

//This if statement will assign the head node the first item that is inserted into the linked list in order to begin the queue
if(head == NULL){
Node* newNode = firstNode(jd, pv, at, wt);
}
// If the head node's priority is greater than the next node then they are swapped.
else if((*head)->priority_value > pv){
tempNode->next = *head;
(*head) = tempNode;
}
else{
// If the head node is not null and its priority is less than the current node's priority that was just passed through the function then the head node stays as the highest priority while the the node that was just passed into this function gets compared to other nodes in the list.
while (startNode->next != NULL && startNode->next->priority_value < pv){
startNode = startNode->next;
}

// Either at the ends of the list
// or at required position
tempNode->next = startNode->next;
startNode->next = tempNode;
}
}
// This checks to see how many nodes are in the list and then returns that value
int LinkedList::getLength(Node* head){
Node *list = head;
int count = 0;
// the count variable is used to count the number of nodes while the while loop goes through each node in the list until it reaches the nullptr
while(list){
list = list->next;
count += 1;
}
return count;
}
//This boolean function checks to see if the queue is empty and returns either true or false back to main
bool LinkedList::isEmpty(Node* head){
return head == nullptr;
}
//This function displays the job's id, date, and its level of priority in the queue
void LinkedList::display(Node* head){
ofstream outputFile ("output.txt");
Node* list = head;
outputFile << "Job ID  " << setw(10) << "Arrival Time  " << setw(10) << "Priority ID  " << endl;
while(list){
if (head == nullptr){
isEmpty(list);
}
else{
outputFile << list->jobID << " " << setw(10) << (now->tm_year + 1900) << "-" << (now->tm_mon +1)  << "-" << now->tm_mday << setw(5) << list->priority_value << endl;
list = list->next;
}
}
}

我试着去构建设置,看看是否有什么没有正确设置,但所有设置都默认为c++。

OK算出来了(如果有错误信息会更快)。

第一个cpp文件

time_t t = time(0);
tm* now = localtime(&t);
这是第二个CPP文件
time_t t = time(0);
tm* now = localtime(&t);

tnow都在两个cpp文件中全局定义。所以你会得到一个重复的符号错误。

由于您似乎只在第二个cpp文件中使用这些变量,因此从第一个cpp文件中删除它们应该可以解决您的问题。

最新更新