'multiple definition of `function' error occurring on the same line as "first defined here"

error log

paging.c: In function ‘setup_paging_structures’:
paging.c:7: warning: implicit declaration of function ‘printf’
rm -f bootimg
gcc -nostdlib -static boot.o paging.o x86_desc.o i8259.o kernel.o lib.o paging.o tests.o -Ttext=0x400000 -o bootimg
paging.o: In function `setup_paging_structures':
/workdirmain/work/mp3_group_31/student-distrib/paging.c:4: multiple definition of `setup_paging_structures'
paging.o:/workdirmain/work/mp3_group_31/student-distrib/paging.c:4: first defined here
paging.o: In function `initialize_paging':
/workdirmain/work/mp3_group_31/student-distrib/paging.c:13: multiple definition of `initialize_paging'
paging.o:/workdirmain/work/mp3_group_31/student-distrib/paging.c:13: first defined here
collect2: ld returned 1 exit status
make: *** [bootimg] Error 1

Here's what my paging.h file looks like:

#ifndef _PAGING_H
#define _PAGING_H

#include "types.h"

#define TOTAL_ENTRIES 1024

extern void setup_paging_structures();
extern void initialize_paging();

#endif

Paging.c below:

#include "paging.h" //include header files

void setup_paging_structures(){
    int i;
    for (i = 0; i < TOTAL_ENTRIES; i++){
        printf("weird");
    }
    return;
}

void initialize_paging(){
    setup_paging_structures();
    return;
}

Note, I have not called the functions yet.

The command I'm using is "sudo make" (Makefile was given to me. I'm pretty sure I'm not supposed to modify it):

# Makefile for OS project
# To build, first `make dep`, them `make`. Everything should be automatic.
# Will compile all *.c and *.S files in the current directory.


# Flags to use when compiling, preprocessing, assembling, and linking
CFLAGS+=-Wall -fno-builtin -fno-stack-protector -nostdlib
ASFLAGS+=
LDFLAGS+=-nostdlib -static
CC=gcc

#If you have any .h files in another directory, add -I<dir> to this line
CPPFLAGS+=-nostdinc -g

# This generates the list of source files
SRC=$(wildcard *.S) $(wildcard *.c) $(wildcard */*.S) $(wildcard */*.c)

# This generates the list of .o files. The order matters, boot.o must be first
OBJS=boot.o
OBJS+=$(filter-out boot.o,$(patsubst %.S,%.o,$(filter %.S,$(SRC))))
OBJS+=$(patsubst %.c,%.o,$(filter %.c,$(SRC)))

bootimg: Makefile $(OBJS)
    rm -f bootimg
    $(CC) $(LDFLAGS) $(OBJS) -Ttext=0x400000 -o bootimg
    sudo ./debug.sh

dep: Makefile.dep

Makefile.dep: $(SRC)
    $(CC) -MM $(CPPFLAGS) $(SRC) > $@

.PHONY: clean
clean:
    rm -f *.o */*.o Makefile.dep

ifneq ($(MAKECMDGOALS),dep)
ifneq ($(MAKECMDGOALS),clean)
include Makefile.dep
endif
endif

edit: I added updates to my post including the actual directories, the entire error log, and the contents of the Makefile I am using. This is also for a class that I'm currently taking, hence some of the things that were automatically given to me.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source