I'm trying to compile a C++ program that utilizes sqlite3. I'm using this makefile:
CXX = g++ 
CC = gcc 
CFLAGS = -c -O2 
CXXFLAGS = -Wall -O3 -std=c++11
SQLFLAGS = -DSQLITE_THREADSAFE=0
OUTPUTBIN = bot
OUTPUTDIR = ./bin/
MKDIR = mkdir -p $(OUTPUTDIR) 
OBJECTC = sqlite3.o
CSOURCES = sqlite3.c  
CXXSOURCES = main.cpp bot.cpp
all: project
project: createdir sql compilecpp
createdir:
    $(MKDIR)
sql:
    $(CC) $(CSOURCES) $(SQLFLAGS) $(CFLAGS) -o $(OUTPUTDIR)$(OBJECTC)
compilecpp:
    $(CXX) $(OUTPUTDIR)$(OBJECTC) $(CXXSOURCES) $(CXXFLAGS) -o $(OUTPUTDIR)$(OUTPUTBIN)
But outputs these errors:
akf@akf-v5 ~/Documents/Proletarian/c++ $ make
mkdir -p ./bin/ 
gcc  sqlite3.c   -DSQLITE_THREADSAFE=0 -c -O2  -o ./bin/sqlite3.o
g++  ./bin/sqlite3.o main.cpp bot.cpp -Wall -O3 -std=c++11 -o ./bin/bot
./bin/sqlite3.o: In function `unixDlError':
sqlite3.c:(.text+0x170f4): undefined reference to `dlerror'
./bin/sqlite3.o: In function `unixDlClose':
sqlite3.c:(.text+0x5de9): undefined reference to `dlclose'
./bin/sqlite3.o: In function `unixDlSym':
sqlite3.c:(.text+0x5e01): undefined reference to `dlsym'
./bin/sqlite3.o: In function `unixDlOpen':
sqlite3.c:(.text+0x5e21): undefined reference to `dlopen'
collect2: error: ld returned 1 exit status
make: *** [compilecpp] Error 1
I'm extremely confused as to what's causing this. I can see that sqlite3 is a C program, but I didn't think it would cause any issues.
The error messages tell that dlerror, dlclose, dlsym and dlopenare used but can't be found. Those functions are part of the dynamic link loader. You have to link the dynamic linker, too. Add -ldl to your link flags. See also dlopen manpage for your system.
A bit late, but - the simplest possible Makefile:
all: sqlite3
sqlite3: sqlite3.o shell.o
    gcc sqlite3.o shell.o -lpthread -ldl -o sqlite3
sqlite3.o: sqlite3.c sqlite3.h
    gcc -c sqlite3.c -lpthread -ldl -o sqlite3.o
shell.o: shell.c
    gcc -c shell.c -lpthread -o shell.o
clean:
    rm *.o
    rm sqlite3
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With