Question:
c++ linker error -unresolved externals?
kievar
2010-04-21 19:38:20 UTC
I'm working on a c++ application that will sort arrays and it appears when i goto compile it currently i get a linker error. and not sure why, i may be missing an include file or something, i don't know.

below is my code, any help would be great.
------------

#include
#include
#include
#include

using namespace std;

typedef string* StrPtr;
typedef double* DoublePtr;

int readData(StrPtr &dates, DoublePtr &prices);
void selectionSort(StrPtr dates, DoublePtr prices, vector numPrices);

int main()
{
vector numPrices;
StrPtr dates;
DoublePtr prices;
readData (dates, prices);
selectionSort(dates, prices, numPrices);
}

int readData(StrPtr &dates, DoublePtr &prices)
{
int numRecords = 0;
ofstream inFile;

inFile.open("PriceHistory.txt");
if (inFile.fail())
{
cout << "Error: Failed to open input file." << endl;
exit(1);
}

inFile << numRecords;
dates = new string[numRecords];
prices = new double[numRecords];

inFile << dates;
inFile << prices;

return numRecords;
}

void selectionSort(StrPtr dates, DoublePtr prices, int numPrices)
{
double minValue = 0;
int minIndex = 0;
double tmp = 0;

for (int i = 0; i < numPrices - 1; i++) {
minValue = prices[i];
minIndex = i;
for (int j = i + 1; j < numPrices; j++)
if (prices[j] < minValue) {
minValue = prices[j];
minIndex = j;
} // end if
tmp = prices[i];
prices[i] = prices[minIndex];
prices[minIndex] = tmp;
}
}
Four answers:
?
2010-04-21 20:12:56 UTC
Unresolved External means the program is calling a function that's not provided either by your code or the system.



It's hard to tell for sure without seeing the linker error messages, but I'd bet your definition of selectionSort(), because of the difference in the third parameter type, isn't satisfying the call of the function.



Hope that helps.
JoelKatz
2010-04-21 19:39:56 UTC
You forgot to tell us what error you are getting. Also, you're missing a #include of ''.



The biggest problem is that your code is inconsistent about what the third parameter to 'selectionSort' is. Is it an 'int' or a 'vector'?
2016-12-03 13:55:57 UTC
It in all probability is a difficulty with the linker. pass to undertaking - properties - configuration properties - linker to determine the linker settings. alter standard - extra Library Directories in case you may function a itemizing the place your libraries to be included are placed. alter enter - extra Dependencies to incorporate libraries you may link to. make valuable that all and sundry libraries and library directories have been included into your undertaking. If this does not sparkling up the subject, it ought to help to determine the code. :) good success.
tbshmkr
2010-04-21 19:55:03 UTC
Post the error messages.

=

Add #include


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...