"Undefined character <function> first link in file <file>" link error
I am writing my first C program for a class; I was able to align most of the syntax errors, but I get a weird error when gcc tries to link object files together. It prints exactly as shown below:
gcc -o proj04.support.o proj04.driver.o
Undefined first referenced
symbol in file
convert proj04.driver.o
I looked through a few answers, but no one makes any sense to me. I will post the files that I use to make the program below, and if you have an answer, I would really appreciate help. This seems to be a fairly simple mistake, so I probably didn’t do something stupid.
Makefile (post this first, because I suspect the problem is here)
# Comments
# Comments
proj04: proj04.support.o proj04.driver.o
gcc -o proj04.support.o proj04.driver.o
proj04.support.o: proj04.support.c
gcc -Wall -c proj04.support.c
proj04.driver.o: proj04.driver.c
gcc -Wall -c proj04.driver.c
( , , ):
int convert( int, unsigned, char[], int )
#include <stdio.h>
#include "/user/cse320/Projects/project04.support.h"
#include <string.h>
void formatdisplay( char[], int );
int convert( int I, unsigned base, char result[], int display )
{
int quotient, dividend, remainder;
const int divisor = base;
int count = 0;
char ending[] = " base ";
dividend = I;
remainder = 0;
quotient = 1;
while (quotient != 0)
{
if (count <= strlen(result))
{
quotient = (dividend / divisor);
remainder = (dividend % divisor);
//convert to ascii char
result[count] = remainder;
count++;
}
}
formatdisplay ( result, display );
strrev(result);
if ( I >= 0 ) { result[0] = '+'; }
if ( I < 0 ) { result[0] = '-'; }
printf( "%s" , strcat (result, ending));
}
void formatdisplay ( char str[], int disp )
{
if ( disp < 0 )
{
unsigned i = 0;
for ( i; i < strlen(str)-1; i++)
{
if ( str[i] = '\0') { str[i] = '0'; }
}
}
if ( disp >= 0 )
{
unsigned i = 0;
for ( i; i < strlen(str)-1; i++)
{
if ( str[i] = '\0') { str[i] = ' '; }
}
}
}
( )
#include <stdio.h>
#include "/user/cse320/Projects/project04.support.h"
int main () {
char Result1[32];
int T = convert(10, 2, Result1, 1);
}
I am not an expert, but like Andreas Joensson (who, judging by the name of the function, writes the same program as me) says above, this problem occurs when there is some discrepancy between the declaration and use of the function.
Your convert function is declared as returning an int, but I cannot find any return value. This can be a problem.