【发布时间】:2011-02-18 00:13:28
【问题描述】:
我正在用 C 语言编写我的第一个课程;我已经设法消除了大多数语法错误,但是当 gcc 尝试将目标文件链接在一起时,我遇到了一个奇怪的错误。它的打印结果完全如下:
gcc -o proj04.support.o proj04.driver.o
Undefined first referenced
symbol in file
convert proj04.driver.o
我环顾四周寻找了一些答案,但对我来说没有一个真正有意义。我将在下面发布我用来制作程序的文件,如果您得到答案,我将非常感谢您的帮助。这似乎是一个非常基本的错误,所以这可能是我没有做的傻事。
Makefile(先发这个是因为我怀疑问题出在这里)
# 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);
}
【问题讨论】:
-
您确定您正确引用了
project04.support.h文件吗?函数声明后好像少了分号。