C언어 multiple definition of (함수) 오류

niceedu의 이미지

함수를 선언한 헤더파일 header.h

#ifndef __FUNCTION_H__
#define __FUCNTION_H__
 
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
 
#define TRUE 1
#define FALSE 0
#define MAX_COMMAND_SIZE 100
 
char COMMAND[MAX_COMMAND_SIZE];
 
int what_is_command(char command[]);
 
void func_help(void);
 
 
 
#endif

함수를 정의한 define.c 파일

#include "header.h"
 
int what_is_command(char command[]){
 
        if(strcmp(command,"help") == 0 || strcmp(command,"h") == 0)
                return 1;
 
        else if(strcmp(command, "dir")==0|| strcmp(command,"d") == 0)
                return 2;
 
        else if(strcmp(command,"quit" )==0|| strcmp(command,"q")==0)
                return 3;
        else if(strcmp(command,"history")==0|| strcmp(command,"hi")==0)
                return 4;
        else if(strcmp(command,"dump" )==0|| strcmp(command,"du")==0)
                return 5;
        else if(strcmp(command,"edit" )==0|| strcmp(command,"e")==0)
                return 6;
        else if(strcmp(command,"fill" )==0|| strcmp(command,"f")==0)
                return 7;
        else if(strcmp(command,"reset" )==0)
                return 8;
        else if(strcmp(command,"opcode" )==0)
                return 9;
        else if(strcmp(command,"opcodelist")==0)
                return 10;
        else
                return 0;
 
 
}
 
void func_help(void){
        printf("h[elp]\n");
        printf("d[ir]\n");
        printf("q[uit\n]");
        printf("hi[story\n");
        printf("du[mp] [start, end]\n");
        printf("e[dit] address, value\n");
        printf("f[ill] start, end, value");
        printf("reset");
        printf("opcode mnemonic\n");
        printf("opcodelist\n");
}

main함수가 담긴 파일 main.c

#include "header.h"
#include "define.c"
 
 
 
 
int main(){
 
    while(TRUE){
 
        printf("sicsim> ");
        scanf("%s", COMMAND);
 
        switch(what_is_command(COMMAND)){
                case 1 : func_help(); break;
                default: break;
     }
 
}
 
return 0;
}

Makefile의 내용

main.out: main.o define.o
        gcc -o main.out main.o define.o
define.o: define.c header.h
        gcc -c define.c
main.o: main.c define.c header.h
        gcc -c main.c define.c

오류내용

define.o: In function `what_is_command':
define.c:(.text+0x0): multiple definition of `what_is_command'
main.o:main.c:(.text+0x0): first defined here

define.o: In function `func_help':
define.c:(.text+0x1d0): multiple definition of `func_help'
main.o:main.c:(.text+0x1d0): first defined here
collect2: error: ld returned 1 exit status
Makefile:2: recipe for target 'main.out' failed
make: *** [20120121.out] Error 1
cse20120121@cspro:~/sp20120121_proj1$

분명 중복 오류를 잘 피할 수 있을거라 생각했는데 위와같은 오류가 발생했습니다.
makefile에서 잘못된건가요? ㅠ_ㅠ

익명 사용자의 이미지

main과 define을 따로 컴파일하고 링크를 하던지 아니면 그냥 한 커맨드에서 컴파일하던지 선택을 해야지요. 지금은 define을 두 번 컴파일하잖아요. define.o 타겟에서 한 번 하고 main.o 타겟에서 한 번 더 하고.

익명 사용자의 이미지

#include "define.c" 부분을 지우세요.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.