first link in file " link error I am writing my first C program for a class; I was able to align most of ...">

"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);
}
+3
3

, , , Makefile:

proj04: proj04.support.o proj04.driver.o
        gcc -o proj04.support.o proj04.driver.o

-o gcc , . , gcc proj04.driver.o, proj04.support.o.

gcc -o proj04 proj04.support.o proj04.driver.o .

+3

.

Undefined first referenced symbol in file isThreeOfAKind /var/tmp//ccIQWbaj.o

, , . :

 void isThreeOfAKind (void);
 void isThreeOfAkind {}

K k.

, k K, .

, , - .

+3

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.

+3
source

Source: https://habr.com/ru/post/1792942/


All Articles