Issue
All of my files were on the same folder and it all worked great, now i organized it as i think would be correct but now i cant finish the compilation
this is the tree:
├── assembler.c
├── assembler_utils
│ ├── assembler_utils.c
│ ├── assembler_utils.h
├── error_handler
│ ├── error_handler.c
│ ├── error_handler.h
├── file_utils
│ ├── file_utils.c
│ ├── file_utils.h
├── first
│ ├── first_pass.c
│ ├── first_pass.h
├── globals.h
├── in_utils
│ ├── input_utils.c
│ ├── input_utils.h
├── makefile
├── management
│ ├── table_management.c
│ ├── table_management.h
├── pre
│ ├── pre_assembler.c
│ ├── pre_assembler.h
└── sec
├── second_pass.c
├── second_pass.h
i changed all of the includes on my files to look like this(example):
previously:
#include "pre_assembler.h"
now:
#inclue "../pre/pre_assembler.h"
(.. - to go back one directory and then to the proper one)
i ran the command to get the proper compilation command:
gcc -MM assembler.c assembler_utils/assembler_utils.c error_handler/error_handler.c file_utils/file_utils.c first/first_pass.c in_utils/input_utils.c management/table_management.c pre/pre_assembler.c sec/second_pass.c
and this is how the makefile looks:
CC = gcc
EXEC = assembler
OBJS = assembler.o assembler_utils/assembler_utils.o error_handler/error_handler.o file_utils/file_utils.o first/first_pass.o in_utils/input_utils.o pre/pre_assembler.o sec/second_pass.o management/table_management.o
COMP_FLAG = -ansi -Wall -pedantic
DEBUG_FLAG = -g
$(EXEC): $(OBJS)
$(CC) $(COMP_FLAG) $(DEBUG_FLAG) $(OBJS) -o $@ -lm
assembler.o: assembler.c pre/pre_assembler.h \
management/table_management.h globals.h first/first_pass.h \
sec/second_pass.h file_utils/file_utils.h in_utils/input_utils.h
$(CC) $(COMP_FLAG) $(DEBUG_FLAG) -c assembler.c -o assembler.o -lm
assembler_utils/assembler_utils.o: assembler_utils/assembler_utils.c \
assembler_utils/assembler_utils.h globals.h
$(CC) $(COMP_FLAG) $(DEBUG_FLAG) -c $< -o $@
error_handler/error_handler.o: error_handler/error_handler.c \
error_handler/error_handler.h globals.h
$(CC) $(COMP_FLAG) $(DEBUG_FLAG) -c $< -o $@
file_utils/file_utils.o: file_utils/file_utils.c \
file_utils/file_utils.h globals.h management/table_management.h
$(CC) $(COMP_FLAG) $(DEBUG_FLAG) -c $< -o $@
first/first_pass.o: first/first_pass.c first/first_pass.h \
first/../globals.h management/table_management.h \
in_utils/input_utils.h assembler_utils/assembler_utils.h
$(CC) $(COMP_FLAG) $(DEBUG_FLAG) -c $< -o $@
in_utils/input_utils.o: in_utils/input_utils.c in_utils/input_utils.h \
error_handler/error_handler.h globals.h
$(CC) $(COMP_FLAG) $(DEBUG_FLAG) -c $< -o $@
pre/pre_assembler.o: pre/pre_assembler.c pre/pre_assembler.h \
management/table_management.h globals.h in_utils/input_utils.h \
file_utils/file_utils.h error_handler/error_handler.h \
assembler_utils/assembler_utils.h
$(CC) $(COMP_FLAG) $(DEBUG_FLAG) -c $< -o $@
sec/second_pass.o: sec/second_pass.c sec/second_pass.h \
management/table_management.h globals.h in_utils/input_utils.h \
error_handler/error_handler.h assembler_utils/assembler_utils.h
$(CC) $(COMP_FLAG) $(DEBUG_FLAG) -c $< -o $@
management/table_management.o: management/table_management.c \
management/table_management.h globals.h
$(CC) $(COMP_FLAG) $(DEBUG_FLAG) -c $< -o $@
clean:
-rm $(EXEC) $(OBJS)
I get issues where it claims that i have multiple definitions of the same function, but it points to the first place (for example):
/usr/bin/ld: first/first_pass.o: in function `is_valid_symbol_macro_name':
{path}/first/../assembler_utils/assembler_utils.c:50: multiple definition of `is_valid_symbol_macro_name'; {path}/assembler_utils/assembler_utils.c:50: first defined here
I tried to consult with chatGPT on the makefile and my files since i dont see any issue there but hes no assisting that much
Solution
The error message indicates that you have two definitions of the same function. One source location given seems pretty normal: {path}/assembler_utils/assembler_utils.c:50
. But the other is a bit surprising: {path}/first/../assembler_utils/assembler_utils.c:50
.
Note in particular that those seem to contain two different paths to the same file. I don't see anything in the makefile that would explain multiple compilation of the same file, but you could get that effect by both compiling a file and #include
ing it in a separate file that you also compile. Since you had to modify your #include
statements in the course of your reorganization, it seems likely that you did so incorrectly in at least one place.
Look for a place where you mistakenly #include "../assembler_utils/assembler_utils.c"
instead of #include "../assembler_utils/assembler_utils.h"
. Based on the form of the second path given in the error message, you'll probably find the error in first/first_pass.c
and / or first/first_pass.h
Answered By - John Bollinger Answer Checked By - Timothy Miller (WPSolving Admin)