2012-03-22 68 views
0

未定义的符号正在此错误对我的代码:用于建筑

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; 
} 
+0

'void spendDollars(budget *,double)'的定义在哪里? – 2012-03-22 23:50:08

回答

3

该错误消息告诉你到底是什么问题。您的程序中没有称为spendDollars()的功能。那么,你这样做,但它被评论了。注释掉的函数与您使用的签名不匹配,所以看起来您有一些代码可供编写。

+0

清理了代码并发现了问题。谢谢。 – pdenlinger 2012-03-23 01:42:09