LNK2019 Error
Aug 14, 2015 at 10:11pm UTC
I am getting this error in my compiler and unable able to figure out what the issue is so far..
Error 1 error LNK2019: unresolved external symbol "int __cdecl showBooksByAuthor(int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?showBooksByAuthor@@YAHHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main
Error 2 error LNK1120: 1 unresolved externals 1 1
Here is just the beginning of what I have. What is that error pointing to?!?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
// Declare Variables
const int ARRAY_SIZE = 1000;
int showBooksByAuthor(int count, string name);
int showBooksByTitle(int count, string title);
string pathName;
string bookTitle[ARRAY_SIZE];
string bookAuthor[ARRAY_SIZE];
// Functions
int main()
{
// char backupFile;
char reply;
int count = 0;
string name;
string title;
do
{
// Output
cout << "Welcome to Edward's Libarary Database. " << endl;
cout << "Please enter the name of the backup file: " ;
// cin >> backupFile;
cout << "Enter Q to (Q)uit, Search (A)uthor, Search (T)itle, (S)how all: " ;
cin >> reply;
// Selection
switch (reply)
{
case 'a' :
case 'A' :
char nameAuthor;
cout << "Author's Name: " ;
cin >> nameAuthor;
if (count <= 0)
{
cout << "No Author found!" << endl;
}
else
{
cout << showBooksByAuthor(count, name) << "found! " << endl;
}
break ;
case 't' :
case 'T' :
char nameTitle;
cout << "Title: " ;
cin >> nameTitle;
break ;
case 's' :
case 'S' :
break ;
case 'q' :
case 'Q' :
break ;
default :
cout << "Invalid Input." << endl;
break ;
}
} while (reply != 'Q' && reply != 'q' );
system("pause" );
return 0;
}
int loadData(string pathname)
{
int count = 0;
ifstream inFile;
inFile.open(pathName);
if (!inFile)
{
cout << "Cannot open backup file" << endl;
return -1;
}
else
{
cout << "File opened" << endl;
}
while (!inFile.eof())
{
getline(inFile, bookTitle[count]);
getline(inFile, bookAuthor[count]);
count++;
}
return count;
}
void showAll(int count)
{
int i;
for (i = 0; i < count; i++)
{
// cout << bookTitle[i] << " " << "(" << bookAuthor[i] << ")" << endl;
}
}
Aug 14, 2015 at 10:20pm UTC
Have you defined
1 2
int showBooksByAuthor(int count, string name);
int showBooksByTitle(int count, string title);
. If so make sure to pass the files they are defined in to the compiler. Also a tip would be to declare functions in a header.
e.g
g++ main.cpp showBooks.cpp ....
The code you have provided does not defined them it just declares them.
Last edited on Aug 14, 2015 at 11:29pm UTC
Aug 14, 2015 at 10:20pm UTC
You are trying to call nonexisting function showBooksByAuthor at line 60
Aug 14, 2015 at 10:45pm UTC
Ah! I see it now. Thank you!
Topic archived. No new replies allowed.