Compiler Error: Undefined symbols for architecture

2019-09-01 16:41发布

问题:

I'm getting this weird error when I try to compile.

Undefined symbols for architecture x86_64: readRecipe(std::basic_istream<char, std::char_traits<char> >&, std::basic_ostream<char, std::char_traits<char> >&, Cookbook&), referenced from: _main in cclDKibb.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status

This is the function that it is referring to:

void readRecipe(std::ifstream &istr, std::ofstream &ostr, Cookbook &cookbook)
{
    int units; std::string name, name2; 
    // Read recipe name. 
    istr >> name; 

     // Build the new recipe Recipe r(name);

    while (1)
    { 
        istr >> units; 
        if (units == 0)
            break; 
        assert (units > 0);

        istr >> name2; 
        Ingredient i(name2, units); 
        r.addIngredient(i);
    }

    // Add it to the list. 
    if (cookbook.addRecipe(r, ostr))
        ostr << "Recipe for " << name << " added" << std::endl; 
    else 
        ostr << "Recipe for " << name << "already exists" << std::endl;
}

Any ideas?

回答1:

I figured it out. My prototype for the function was messed up.