未定义的架构符号

时间:2012-03-22 23:47:23

标签: objective-c xcode

我的代码收到此错误:

Undefined symbols for architecture x86_64:
  "_spendDollars", referenced from:
      _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)

检查了代码,但找不到错误。这是:

#import <Foundation/Foundation.h>

typedef struct {
    float exchangeRate;
    double budget;
    //double euroTransaction;
    double exchangeTransaction;
} budget;

//budget vacationBudget;
budget vacationBudgetEurope;
budget vacationBudgetEngland;

//void spendDollars (double dollars);

//void chargeEuros (double euros);

void spendDollars(budget* theBudget, double dollars);
void chargeForeignCurrency(budget* theBudget, double foreignCurrency);

int main(int argc, const char * argv[])
{

        //budget vacationBudget;

        //vacationBudget.exchangeRate = 1.2500;
    vacationBudgetEurope.budget = 1000;
        //vacationBudget.budget = 1000.00;
    vacationBudgetEurope.budget = 1000.00;
        //double numberDollars = 100;
    double numberDollarsInEuroland = 100;
    double numberEuros = 100;

    vacationBudgetEngland.exchangeRate = 1.5000;
    vacationBudgetEngland.budget = 2000.00;
    double numberDollarsInPoundland = 100;
    double numberPounds = 100;

        //vacationBudget.budget -= 100.00;

    //spendDollars(numberDollars);
    spendDollars(&vacationBudgetEurope, numberDollarsInEuroland);


    //NSLog(@"Converting %.2f US dollars into euros leaves $%.2f dollars", numberDollars, vacationBudget.budget); 
    NSLog(@"Converting %.2f US dollars into euros leaves $%.2f", numberDollarsInEuroland, vacationBudgetEurope.budget);
    //chargeEuros(numberEuros);
    chargeForeignCurrency(&vacationBudgetEurope, numberEuros);
    //NSLog(@"Charging %.2f euros leaves $%.2f", numberEuros, vacationBudget.budget);
    NSLog(@"Charging %.2f euros leaves $%.2f", numberEuros, vacationBudgetEurope.budget);
    spendDollars(&vacationBudgetEngland, numberDollarsInPoundland);
    NSLog(@"Converting %.2f US dollars into pounds leaves $%.2f", numberDollarsInPoundland, vacationBudgetEngland.budget);
    chargeForeignCurrency(&vacationBudgetEngland, numberPounds);
    NSLog(@"Charging %.2f pounds leaves $%.2f", numberPounds, vacationBudgetEngland.budget);


    return 0;
}

//void spendDollars (double dollars) {
//    vacationBudget.budget -= dollars;
//}

void chargeForeignCurrency (budget* theBudget, double foreignCurrency) {
    theBudget -> exchangeTransaction = foreignCurrency*theBudget -> exchangeRate;
    theBudget ->budget -= theBudget -> exchangeTransaction;
}

1 个答案:

答案 0 :(得分:3)

该错误消息正好告诉您问题所在。您的程序中没有名为spendDollars()的函数。好吧,你这样做,但它被评论出来了。注释掉的函数与您正在使用的签名不匹配,因此看起来您要编写一些代码。

相关问题