"未定义符号< function>首先在文件< file>"中引用链接错误 [英] "Undefined symbol <function> first referenced in file <file>" link error

查看:66
本文介绍了"未定义符号< function>首先在文件< file>"中引用链接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C语言编写我的第一个程序.我设法消除了大多数语法错误,但是当gcc尝试将目标文件链接在一起时,我遇到了一个奇怪的错误.它的打印如下:

I'm writing my first program in C for a class; I've managed to even out most of the syntax errors, but I'm getting a strange error when gcc tries to link the object files together. It prints exactly like below:

gcc -o proj04.support.o proj04.driver.o
Undefined                       first referenced
 symbol                             in file
convert                             proj04.driver.o

我一直在寻找一些答案,但对我来说真的没有任何意义.我将下面用来制作程序的文件发布在下面,如果您有答案,我将非常感谢您的帮助.这似乎是一个非常基本的错误,所以这可能是我没有做过的愚蠢的事情.

I've looked around for a few answers, but none really make sense to me. I'll post the files I'm using to make the program below, and if you've got the answer I would really appreciate the help. It seems to be a pretty basic error, so it's probably something silly I didn't do.

Makefile (首先发布此信息,因为我怀疑问题在这里)

Makefile (posting this first because I suspect the issue 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

头文件(由教授提供,不可更改,长一行):

Header file (provided by the professor, unchangeable, one line long):

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 had the almost the same problem.

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

我的问题是我错过了其中一个函数的字母,因此声明和函数未对齐.例如:

My problem was that I had missed on a letter in one of my functions, so the declaration and the function misaligned. Ex:

 void isThreeOfAKind (void);
 void isThreeOfAkind {}

缺少大写字母K,而是写了小写字母k.

Missed the uppercase K, and wrote lowercase k instead.

将k更改为大写K后,它可以很好地编译.

After I changed the k to a uppercase K it compiled fine.

我不知道它是否有帮助,但这可能就这么简单.

I dont know if it helps, but it could be something as easy as that.

这篇关于&quot;未定义符号&lt; function&gt;首先在文件&lt; file&gt;&quot;中引用链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆