我的代码:
#include <iostream>
using namespace std;
int main ()
{
// Declare named constants for tax and tip rates
const double TIP_RATE = 0.20; // 20%
const double TAX_RATE = 0.0675; // 6.75%
// Declare variables for inputs and results
double mealCharge;
double tax, tip, totalBill; // Results
// Initialize all input variables
cout << "What is the cost of the meal?: $ ";
cin >> mealCharge;
tip = mealCharge * TIP_RATE;
tax = mealCharge * TAX_RATE;
totalBill = mealCharge + tip + tax;
cout << "Your meal cost is: $ " << mealCharge << endl;
cout << "Your tax amount is: $ " << tax << endl;
cout << "The tip you should pay is: $ " << tip << endl;
cout << "Your total cost for the meal is: $ " << totalBill << endl;
return 0;
}
错误消息:
复制符号_main in:
/Users/*******/Library/Developer/Xcode/DerivedData/C++_Error_Resolution-eiuslwrjycbgywdfhqxyxsmklwep/Build/Intermediates/C++ Error Resolution.build/Debug/C++ Error Resolution.build/Objects-normal/x86_64/main.o
/Users/********/Library/Developer/Xcode/DerivedData/C++_Error_Resolution-eiuslwrjycbgywdfhqxyxsmklwep/Build/Intermediates/C++ Error Resolution.build/Debug/C++ Error Resolution.build/Objects-normal/x86_64/fixingErrors.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
每当我尝试在xcode上编写和构建程序时,我就在xcode中编写了大量的javascript文件而没有任何问题。我知道windows pc的编码优越,但在我看来,xcode应该能够处理一个非常基本的C ++程序。
有没有办法解决这个问题,还是我必须将笔记本电脑带到苹果公司,看看他们能做些什么呢?
答案 0 :(得分:0)
正如@aschepler所说,您将main.o
和fixingErrors.o
链接在一起,每个对象定义main
。
将两个目标文件(对于这个简单的示例不必要,但对于更复杂的示例非常有用)链接在一起,但是不能将两个定义相同功能的目标文件链接在一起。