collect2: ld returned 1 exit status 에러

익명 사용자의 이미지

안녕하세요 make시스템으로 컴파일하는데 에러가 나서 여쭤봅니다 ㅠ

-bash-3.2$ make
gcc -c recMain.c
gcc -o recMain recMain.o recIO.o
정의되지 않음 첫번째 참조된
기호 파일:
dbAdd recMain.o
ld: 치명적: symbol referencing errors. No output written to recMain
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `recMain'

main 코드는

#include "recIO.h"
 
int main(int argc, char *argv[])
{
        char *file;
        char base[5] = "stdb";
        char c;
 
        if(argc > 1)
                file = argv[1];
        else
        {
                file = base;
                dbcreate(file);
        }
        while(1)
        {
                printf(" 'a' 추가 'q' 검색 'u' 수정 'd' 삭제 'e' 종료\n");
                c = getchar();
                switch (c)
                {
                        case 'a':
                                dbAdd(file);
                                break;
                        case 'q':
                                dbquery(file);
                                break;
                        case 'u':
                                dbupdate(file);
                                break;
                        case 'd':
                                dbdelete(file);
                                break;
                        case 'e':
                                exit(0);
                        default:
                                printf("잘못된 입력입니다.\n");
                }
 
        }
        return 0;
}

입니다.
영어를 잘 못해서 해외 사이트 구글링을 찾아도 알 수가 없네요..
왜 이런 오류가 나는지 설명좀 부탁드립니다 ㅠ

글쓴이의 이미지

본문이 너무 길어질거같아서 답글로 남깁니다.

Makefile:

recMain: recMain.o recIO.o
        gcc -o recMain recMain.o recIO.o
recMain.o: recMain.c recIO.h recIO.c student.h
        gcc -c recMain.c
recIO.o: recIO.c recIO.h student.h
        gcc -c recIO.c

recIO.c ( 학생 정보를 입력,삭제,추가,검색 하는 파일 레코드 )

#include "recIO.h"
 
void dbcreate(char *file)
{
        int fd;
        student rec;
 
        if ((fd = open(file, O_WRONLY | O_CREAT, 0600)) == -1)
        {
                exit(1);
        }
        printf("%-9s %-8s %-4s", "학번", "이름", "점수");
        while(scanf("%d %s %d", &rec.id, rec.name, &rec.score) == 3)
        {
                lseek(fd,(rec.id - START_ID) * sizeof(rec),SEEK_SET);
                write(fd,&rec, sizeof(rec));
        }
        printf("생성 완료\n");
        close(fd);
}
 
void dbquery(char *file)
{
        int fd, id;
        student rec;
 
        if ((fd = open(file, O_WRONLY)) == -1)
        {
                exit(2);
        }
        printf("검색할 학번 입력: ");
        if(scanf("%d",&id) == -1)
        {
                lseek(fd,(id-START_ID)*sizeof(rec),SEEK_SET);
                if((read(fd,&rec,sizeof(rec)) > 0 ) && (rec.name[0] != 0))
                        printf("학번:%d\t 이름:%s\t 점수:%d\n", rec.id, rec.name, rec.score);
                else printf("레코드 %d 없음\n", id);
        }
        else
                printf("입력 오류");
        close(fd);
}
 
void dbdelete(char *file)
{
        int fd,id;
        student rec;
 
        if((fd = open(file,O_WRONLY)) == -1)
        {
                exit(3);
        }
        printf("학번 입력: ");
        while(scanf("%d", &id) == 1)
        {
                if(lockf(fd,F_LOCK,sizeof(rec)) == -1)
                {
                        perror(file);
                        exit(4);
                }
                if((read(fd,&rec,sizeof(rec)) > 0 ) && (rec.name[0] != 0))
                {
                        rec.name[0] = 0;
                        lseek(fd,-sizeof(rec),SEEK_CUR);
                        write(fd,&rec,sizeof(rec));
                        printf("삭제되었습니다.");
                        lockf(fd,F_ULOCK,sizeof(rec));
                } else
                        printf("레코드 %d 없음\n",rec.id);
        }
        close(fd);
}
 
void dbadd(char *file)
{
        int fd;
        student rec;
 
        if((fd = open(file,O_RDWR)) == -1)
        {
                exit(5);
        }
        printf("학번,이름,점수를 입력하세요 : ");
        while(scanf("%d %s %d",&rec.id, rec.name, &rec.score) == 3)
        {
                lseek(fd,(rec.id - START_ID) * sizeof(rec), SEEK_SET);
                if(lockf(fd,F_LOCK,sizeof(rec)) == -1)
                        exit(8);
                else
                {
                        lseek(fd, -sizeof(rec),SEEK_CUR);
                        write(fd,&rec,sizeof(rec));
                        printf("추가되었습니다.\n");
                        lockf(fd,F_ULOCK,sizeof(rec));
                }
        }
        close(fd);
}
 
void dbupdate(char *file)
{
        int fd,id;
        student rec;
 
        if((fd = open(file,O_RDWR)) == -1)
        {
                exit(6);
        }
        printf("수정할 학생의 학번 입력:");
        while(scanf("%d",&id) == 1)
        {
                lseek(fd, (long) (id-START_ID)*sizeof(rec), SEEK_SET);
                if(lockf(fd,F_LOCK,sizeof(rec)) == -1)
                {
                        exit(7);
                }
                if((read(fd,(char *)&rec,sizeof(rec))>0) && (rec.id !=0))
                        printf("학번:%d\t 이름:%s\t 점수:%d\n",
                        rec.id, rec.name, rec.score);
                else
                         printf("레코드 %d 없음 \n",id);
 
                printf("새로운 점수 : ");
                scanf("%d", &rec.score);
                lseek(fd,(long) -sizeof(rec), SEEK_CUR);
                write(fd,(char *) &rec, sizeof(rec));
 
                lseek(fd,(long)(id-START_ID)*sizeof(rec),SEEK_SET);
                lockf(fd,F_ULOCK,sizeof(rec));
                printf("\n수정할 학생의 학번 입력:");
        }
        close(fd);
}

recIO.h

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include "student.h"
 
void dbcreate(char *file);
void dbquery(char *file);
void dbadd(char *file);
void dbdelete(char *file);
void dbupdate(char *file);

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.