MySQL error - program won't compile because of error
<p>We were asked to create a program that accepts input from an html. We were dabbling on mysql/mysql webserver and I was trying to compile this program.  </p>

<pre><code>  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;mysql/mysql.h&gt;

  int processQueryResult(MYSQL *pConn, MYSQL_RES *pRes)
  {
    MYSQL_ROW       aRow;
    unsigned int    iCounter, iTotal;

    aRow = mysql_fetch_row (pRes);
    while (NULL != aRow)
    {
    /* Basic formatting for now */
    iTotal = mysql_num_fields (pRes);
    for (iCounter = 0; iCounter &lt; iTotal; iCounter++)
    {
        /* Check if empty data first before displaying */
        if (NULL != aRow[iCounter])
        {
            printf ("%s\t", aRow[iCounter]);
        }
        else
        {
            printf ("NULL\t");
        }
    } 
    printf ("\n");
    aRow = mysql_fetch_row (pRes);
}

/* Check if no error */
if (mysql_errno (pConn) == 0)
{
    printf ("%lu rows returned\n\n", (unsigned long) mysql_num_rows (pRes));
}

return 0;   
} 

int sendQuery(MYSQL *pConn, char *pCommand)
{
MYSQL_RES   *pRes;

if (mysql_query (pConn, pCommand) != 0) /* the query failed */
{
    return 1;
}
pRes = mysql_store_result (pConn);
if (NULL != pRes) /* a result set was returned */
{
    processQueryResult (pConn, pRes);
    mysql_free_result (pRes);

}
else 
{
    if (mysql_field_count (pConn) == 0)
    {
        /* Modified table like INSERT command */
        printf ("%lu rows affected\n", (unsigned long) mysql_affected_rows(pConn));
    }
    else /* an error occurred */
    {
        return 1;
    }
}

return 0;
} 


int getSQLInput(char *pBuffer)
{
int iCount = 0;
int curData;
do
{
    curData = fgetc(stdin);
    *pBuffer = curData;
} while(*pBuffer == '\n');

do
{
    curData = fgetc(stdin);
    pBuffer[++iCount] = curData;

} while ((curData != '\n') &amp;&amp; (curData != EOF));

if (pBuffer[iCount-1] != ';')
{
    pBuffer[iCount++]= ';';

}
pBuffer[iCount]= '\0';

fputc('\n', stdout);
return iCount;
}
int main(int argc, char **argv)
{
 MYSQL      *pConn;
char        aCommand[1024];
char        aServer[1024];
char        aUser[1024];
char        aPassword[1024];
char        aDatabase[1024];

printf("Enter Server: ");
scanf("%s", aServer);

printf("Enter Database: ");
scanf("%s", aDatabase);

printf("Enter user: ");
scanf("%s", aUser);

printf("Enter password: ");
scanf("%s", aPassword);

pConn = mysql_init(NULL);

/* Connect to database */
if (!mysql_real_connect(pConn, aServer, aUser, aPassword, aDatabase, 0, NULL, 0)) {
    printf("Connect Error: %s\n", mysql_error(pConn));
    return 1;
}

printf("SQL command &gt; ");
getSQLInput(aCommand);
while (strcmp(aCommand, "exit;") != 0)
{
    if (0 != sendQuery(pConn, aCommand))
    {
        printf("QUERY ERROR: %s\n", mysql_error(pConn));
    }
    printf("SQL command &gt; ");
    getSQLInput(aCommand);
}

mysql_close(pConn);
return 0;
} 
</code></pre>

<p>When I try to compile it, it shows this list of errors</p>

<pre><code>cabox@box-codeanywhere:~/workspace$ gcc basic.c -o basic.cgi
/tmp/cct4DDaf.o: In function `processQueryResult':
basic.c:(.text+0x18): undefined reference to `mysql_fetch_row'
basic.c:(.text+0x2d): undefined reference to `mysql_num_fields'
basic.c:(.text+0xad): undefined reference to `mysql_fetch_row'
basic.c:(.text+0xc8): undefined reference to `mysql_errno'
basic.c:(.text+0xd8): undefined reference to `mysql_num_rows'
/tmp/cct4DDaf.o: In function `sendQuery':
basic.c:(.text+0x114): undefined reference to `mysql_query'
basic.c:(.text+0x12b): undefined reference to `mysql_store_result'
basic.c:(.text+0x155): undefined reference to `mysql_free_result'
basic.c:(.text+0x163): undefined reference to `mysql_field_count'
basic.c:(.text+0x173): undefined reference to `mysql_affected_rows'
/tmp/cct4DDaf.o: In function `main':
basic.c:(.text+0x32c): undefined reference to `mysql_init'
basic.c:(.text+0x378): undefined reference to `mysql_real_connect'
basic.c:(.text+0x38c): undefined reference to `mysql_error'
/tmp/ccwRjdCw.o: In function `processQueryResult':
basic.c:(.text+0x18): undefined reference to `mysql_fetch_row'
basic.c:(.text+0x2d): undefined reference to `mysql_num_fields'
basic.c:(.text+0xad): undefined reference to `mysql_fetch_row'
basic.c:(.text+0xc8): undefined reference to `mysql_errno'
basic.c:(.text+0xd8): undefined reference to `mysql_num_rows'
/tmp/ccwRjdCw.o: In function `sendQuery':
basic.c:(.text+0x114): undefined reference to `mysql_query'
basic.c:(.text+0x12b): undefined reference to `mysql_store_result'
basic.c:(.text+0x155): undefined reference to `mysql_free_result'
basic.c:(.text+0x163): undefined reference to `mysql_field_count'
basic.c:(.text+0x173): undefined reference to `mysql_affected_rows'
/tmp/ccwRjdCw.o: In function `main':
basic.c:(.text+0x32c): undefined reference to `mysql_init'
basic.c:(.text+0x378): undefined reference to `mysql_real_connect'
basic.c:(.text+0x38c): undefined reference to `mysql_error'
basic.c:(.text+0x3f4): undefined reference to `mysql_error'
basic.c:(.text+0x44b): undefined reference to `mysql_close'
collect2: error: ld returned 1 exit status
</code></pre>