Introduction
I am experiencing difficulties when using gcc -l.
I have a Makefile that either compiles my files or execute them on qemu. I decided to make a database that storages or reads the users credentials. The db reader file isn't in kernel.c file (programs main file) but in a seperated file called recive.c which afterwards is imported to the kernel.c file.
When running the database reader, recive.c, only by compiling that file using gcc recive.c -l sqlite3
it works well but when I tried to pass that gcc command to my makefile it doesn't.
Structure
Here it is my makefile structure:
compiler
CC = /usr/bin/gcc
linker
LD = /usr/bin/ld
sources
SRC = src
objects
OBJ = obj
compiler flags
CC_FLAGS = $(INCLUDE) $(DEFINES) -m32 -std=gnu99 -ffreestanding -Wall -Wextra
Kernel Compilation
$(OBJ)/kernel.o : $(SRC)/kernel.c
@printf "[ $(SRC)/kernel.c ]\n"
$(CC) $(CC_FLAGS) -l sqlite3 -c $(SRC)/kernel.c -o $(OBJ)/kernel.o
@printf "\n"
What have I Tried
I tried to use the following commands in the makefile
- -l sqlite3
- -lsqlite3
- -L sqlite3
- gcc src/kernel.c -l sqlite3
Error Information
I am using Linux Mint. My terminal Output:
[ linking... ]
/usr/bin/ld -m elf_i386 -T ./config/linker.ld -nostdlib -o out/Terminal.bin obj/asm/entry.o obj/asm/load_gdt.o obj/asm/load_idt.o obj/asm/exception.o obj/asm/irq.o obj/io_ports.o obj/vga.o obj/string.o obj/console.o obj/gdt.o obj/idt.o obj/isr.o obj/8259_pic.o obj/keyboard.o obj/kernel.o
/usr/bin/ld: obj/kernel.o: na função "loginMain":
kernel.c:(.text 0x252): referência não definida para "sqlite3_open"
/usr/bin/ld: kernel.c:(.text 0x26a): referência não definida para "sqlite3_errmsg"
/usr/bin/ld: kernel.c:(.text 0x27d): referência não definida para "fprintf"
/usr/bin/ld: kernel.c:(.text 0x28c): referência não definida para "sqlite3_close"
/usr/bin/ld: kernel.c:(.text 0x2be): referência não definida para "sqlite3_exec"
/usr/bin/ld: kernel.c:(.text 0x2d9): referência não definida para "fprintf"
/usr/bin/ld: kernel.c:(.text 0x2ef): referência não definida para "fprintf"
/usr/bin/ld: kernel.c:(.text 0x2fe): referência não definida para "sqlite3_free"
/usr/bin/ld: kernel.c:(.text 0x30d): referência não definida para "sqlite3_close"
/usr/bin/ld: kernel.c:(.text 0x323): referência não definida para "sqlite3_close"
make: *** [Makefile:49: all] Erro 1
Makefile file
You can find my makefile here: https://pastebin.com/XURDCtcW
CodePudding user response:
Alright, well I attempted to make a sqlite program for fun but the relevant portion to this discussion is the make file, and notice that with the LFLAGS
variable I utilized -lsqlite3
:
CC = g
CFLAGS = -g -Wno-write-strings
LFLAGS = -lsqlite3
DBAPI = dbApi
EXECT = examiner
TESTR = xtest
UTILZ = utilities
all: $(DBAPI).o $(TESTR).o $(UTILZ).o
$(CC) $(CFLAGS) -o $(EXECT).exe $^ $(LFLAGS)
$(DBAPI).o: $(DBAPI).h
$(TESTR).o: $(TESTR).h
$(UTILZ).o: $(UTILZ).h
%.o: %.cpp
$(CC) $(CFLAGS) -c $<
clean:
$(RM) *.o $(EXECT).exe
So to build the object files first I run the following code in order to convert all the *.cpp files into object files with the same name (IE dbApi.cpp gets compiled into a dbApi.o object file):
%.o: %.cpp
$(CC) $(CFLAGS) -c $<
and picks them from the header file. Then with that the default all
, each object file I expect to be present gets added to the final compilation into an executable:
all: $(DBAPI).o $(TESTR).o $(UTILZ).o
$(CC) $(CFLAGS) -o $(EXECT).exe $^ $(LFLAGS)
Which should finally allow for program execution, in my case ./examiner.exe
. There is some redundancy in my make file but it is relatively short and straight forward to follow. Hopefully that helps leads you to a more concrete answer. Let me know.
~X