I'm trying to compile a project in C ++, but it's giving the following error:
Undefined symbols for architecture x86_64: "knapSack(int, int*, int*, int)", referenced from: _main in main-b722ae.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any idea what this might be?
I'm using the MacOs X 10.9 system. Here is the snippet of the code where the error is being pointed out:
// Returns the maximum value that can be put in a knapsack of capacity W
int knapSack(int W, int wt[], int val[], int n)
{
int i, w, profit, cont = 0;
item* K = NULL;
//Build table K[][] in bottom up manner
for (i = 0; i <= n; i++)
{
for (w = 0; w <= W; w++)
{
if (i==0 || w==0)
{
profit = 0;
K = insertItem(profit, K);
}
else if (wt[i-1] <= w)
{
profit = max(val[i-1] + returnItem(K, (i-1), (w-wt[i-1]), W), returnItem(K, (i-1), w, W));
K = insertItem(profit, K);
}
else
{
profit = returnItem(K, (i-1), w, W);
K = returnItem(profit, K);
}
cont++;
if(cont % 1000 == 0)
{
cout << "i = "<< i << "w = " << w << "profit = " << profit << endl;//printf("i = %d, w = %d, profit = %d \n", i, w, profit);
}
}
}
return returnItem(K, (i-1), (w-1), W);
}