KirbyB
KirbyB

Reputation: 3

Apple Mach-O-Linker Error: Variable referenced from (line) not found in architecture x86-64

I'm working on a C++ program for a class project where I'm loading object data from a file into a list. I have it set up so the data reading is done as in member function, and then that object is pushed to the list, and repeat, until there's no more data to load.

I'm getting this error:

Undefined symbols for architecture x86_64:

"Product::Product(Product const&)", referenced from:

std::__1::list ::push_back(Product const&) in Week-2.o

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Main function:

Product temp;
list <Product> allProducts;

if (!temp.loadInitalData())
{
    cout << "There is no Product data available. Try a different option: ";
    cin >> choice;
    repeat = true;
}
else {
     while (temp.loadInitalData())
     {
         allProducts.push_back(temp);   //This is where I'm getting the error
     }
     temp.viewMenu();
     repeat = false;
}

Product's loadInitalData() function:

bool Product::loadInitalData()
{
    bool moreData = true;
    fstream prodDatabase;
    prodDatabase.open("ProductDatabase.csv", ios::out|ios::in|ios::binary);
    if (!prodDatabase)
    {
        cout << "File could not be successfully opened\n";
        moreData = false;
    }
    else
    {
        moreData = loadInitialItemData(prodDatabase);
    }
    return moreData;
}

I have linked "Product.h" in my main.cpp file, as well as . Any suggestions?

Upvotes: 0

Views: 67

Answers (1)

catnip
catnip

Reputation: 25388

You are missing a copy constructor for class Product. There are rules about when the compiler provides one as outlined here:

http://en.cppreference.com/w/cpp/language/copy_constructor

but you might need to write one anyway, if copying a Product object is a non-trivial operation.

Consider also making your list a list of Product *'s (i.e. a list of pointers to Product's). This avoids the copy and may well be what you actually want.

Upvotes: 1

Related Questions