我在寫我的第一個程序用C一類「未定義的符號
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`文件嗎?它在函數聲明後似乎缺少分號。 – CiaPan 2014-10-21 06:34:56