我正在使用Xcode 9.0进行学校作业,这是一个简单的命令行程序。在我的一个类中获取与静态类变量相关的这些奇怪错误。我已经阅读了几个类似的问题,并尝试将架构的构建设置从标准架构更改为通用。我也尝试了其他选择,但没有任何东西摆脱错误。我也尝试将构建活动架构更改为“否”。没有帮助。
感谢一些帮助。明天晚上到期的作业。谢谢!
构建错误:
Ld /Users/Kelly/Library/Developer/Xcode/DerivedData/Hw#2_TacoTruck-gzipvvgczeecgketuebotcuumzha/Build/Products/Debug/Hw#2\ TacoTruck normal x86_64
cd "/Users/Kelly/Desktop/Hw#2 TacoTruck"
export MACOSX_DEPLOYMENT_TARGET=10.12
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -L/Users/Kelly/Library/Developer/Xcode/DerivedData/Hw#2_TacoTruck-gzipvvgczeecgketuebotcuumzha/Build/Products/Debug -F/Users/Kelly/Library/Developer/Xcode/DerivedData/Hw#2_TacoTruck-gzipvvgczeecgketuebotcuumzha/Build/Products/Debug -filelist /Users/Kelly/Library/Developer/Xcode/DerivedData/Hw#2_TacoTruck-gzipvvgczeecgketuebotcuumzha/Build/Intermediates.noindex/Hw#2\ TacoTruck.build/Debug/Hw#2\ TacoTruck.build/Objects-normal/x86_64/Hw#2\ TacoTruck.LinkFileList -mmacosx-version-min=10.12 -Xlinker -object_path_lto -Xlinker /Users/Kelly/Library/Developer/Xcode/DerivedData/Hw#2_TacoTruck-gzipvvgczeecgketuebotcuumzha/Build/Intermediates.noindex/Hw#2\ TacoTruck.build/Debug/Hw#2\ TacoTruck.build/Objects-normal/x86_64/Hw#2\ TacoTruck_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -stdlib=libc++ -Xlinker -dependency_info -Xlinker /Users/Kelly/Library/Developer/Xcode/DerivedData/Hw#2_TacoTruck-gzipvvgczeecgketuebotcuumzha/Build/Intermediates.noindex/Hw#2\ TacoTruck.build/Debug/Hw#2\ TacoTruck.build/Objects-normal/x86_64/Hw#2\ TacoTruck_dependency_info.dat -o /Users/Kelly/Library/Developer/Xcode/DerivedData/Hw#2_TacoTruck-gzipvvgczeecgketuebotcuumzha/Build/Products/Debug/Hw#2\ TacoTruck
Undefined symbols for architecture x86_64:
"TacoTruck::idPool", referenced from:
TacoTruck::TacoTruck() in TacoTruck.o
TacoTruck::TacoTruck(int, int, int) in TacoTruck.o
_main in main.o
"TacoTruck::coSales", referenced from:
TacoTruck::TacoTruck(int, int, int) in TacoTruck.o
TacoTruck::soldCarne() in TacoTruck.o
TacoTruck::soldPollo() in TacoTruck.o
TacoTruck::soldVeggie() in TacoTruck.o
TacoTruck::displayCoSales() in TacoTruck.o
_main in main.o
"TacoTruck::coOrders", referenced from:
TacoTruck::TacoTruck(int, int, int) in TacoTruck.o
TacoTruck::soldCarne() in TacoTruck.o
TacoTruck::soldPollo() in TacoTruck.o
TacoTruck::soldVeggie() in TacoTruck.o
TacoTruck::getCoOrders() in TacoTruck.o
TacoTruck::displayCoSales() in TacoTruck.o
_main in main.o
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
HPP文件:
//
// TacoTruck.hpp
// Hw#2 TacoTruck
//
#ifndef TacoTruck_hpp
#define TacoTruck_hpp
#include <stdio.h>
class TacoTruck
{
public:
TacoTruck(); //default constructor
TacoTruck(int carne, int pollo, int veggie); // Overloaded constructor passing in some sales
int getID(); // get Truck ID
void soldCarne(); //set per number orders
void soldPollo(); //set per number orders
void soldVeggie(); //set per number orders
int getCarne(); // get carne orders accessor function
int getPollo(); // get pollo orders accessor function
int getVeggie(); // get veggie orders accessor function
int getTruckOrders(); // get total orders for this truck
void displayTruckSales();
static int getCoOrders(); // get accessor total cumulative orders sold on all trucks
static void displayCoSales();
static int idPool; // Pool to pull ID numbers from
static int coOrders; // Total orders collected across all trucks
static double coSales; // Total Sales across all trucks
private:
int totalCarne; // Number orders of carne asada tacos sold from this truck
int totalPollo; // Number orders of pollo tacos sold from this truck
int totalVeggie; // Number orders of veggie tacos sold from this truck
int id; // Truck ID
};
#endif /* TacoTruck_hpp */
CPP文件:
//
// TacoTruck.cpp
// Hw#2 TacoTruck
//
#include <exception>
#include <iostream>
#include "TacoTruck.hpp"
using namespace std;
#define CARNE_PRICE 5.49
#define POLLO_PRICE 4.49
#define VEGGIE_PRICE 15.59
TacoTruck::TacoTruck()
{
totalCarne = totalPollo = totalVeggie = 0;
id = idPool++;
}
TacoTruck::TacoTruck(int carne, int pollo, int veggie)
{
if (carne < 0)
carne = 0;
if (pollo < 0)
pollo = 0;
if (veggie < 0)
veggie = 0;
totalCarne = carne;
totalPollo = pollo;
totalVeggie = veggie;
coOrders += carne + pollo + veggie;
coSales += carne * CARNE_PRICE + pollo * POLLO_PRICE + veggie * VEGGIE_PRICE;
id = idPool++;
}
int TacoTruck::getID()
{
return id;
}
void TacoTruck::soldCarne()
{
totalCarne++;
coOrders++;
coSales += CARNE_PRICE;
}
void TacoTruck::soldPollo()
{
totalPollo++;
coOrders++;
coSales += POLLO_PRICE;
}
void TacoTruck::soldVeggie()
{
totalVeggie++;
coOrders++;
coSales += VEGGIE_PRICE;
}
int TacoTruck::getCarne()
{
return totalCarne;
}
int TacoTruck::getPollo()
{
return totalPollo;
}
int TacoTruck::getVeggie()
{
return totalVeggie;
}
int TacoTruck::getTruckOrders()
{
return totalCarne + totalPollo + totalVeggie;
}
void TacoTruck::displayTruckSales()
{
cout << "Total orders for Truck " << id << " is " << getTruckOrders() << endl;
cout << "Carne tacos sold: " << getCarne() << endl;
cout << "Pollo tacos sold: " << getPollo() << endl;
cout << "Veggie tacos sold: " << getVeggie() << endl;
};
//static
int TacoTruck::getCoOrders()
{
return coOrders;
}
void TacoTruck::displayCoSales()
{
cout << "Total company sales: $" << coSales << endl;
cout << "Total company orders: " << coOrders << endl;
}
main.cpp中:
//
// main.cpp
// Hw#2 TacoTruck
//
#include <iostream>
#include "TacoTruck.hpp"
int main(int argc, const char * argv[]) {
TacoTruck::idPool = 0;
TacoTruck::coOrders = 0;
TacoTruck::coSales = 0;
TacoTruck successfulTruck(5, 18, 1);
successfulTruck.displayTruckSales();
successfulTruck.soldPollo();
successfulTruck.soldCarne();
successfulTruck.soldCarne();
successfulTruck.soldVeggie();
successfulTruck.displayTruckSales();
TacoTruck::displayCoSales();
TacoTruck badTruck;
badTruck.displayTruckSales();
badTruck.soldVeggie();
badTruck.soldPollo();
badTruck.displayTruckSales();
TacoTruck::displayCoSales();
TacoTruck okTruck;
okTruck.displayTruckSales();
okTruck.soldVeggie();
okTruck.soldVeggie();
okTruck.soldVeggie();
okTruck.soldCarne();
okTruck.soldPollo();
TacoTruck::displayCoSales();
}