繁体   English   中英

C ++编译问题,sqlite3

[英]C++ Compile issues, sqlite3

我正在尝试编译一个利用sqlite3的C ++程序。 我正在使用此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)

但是输出以下错误:

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

我对这是什么原因感到非常困惑。 我可以看到sqlite3是C程序,但是我认为它不会引起任何问题。

错误消息表明已dlerrordlclosedlsymdlopen ,但找不到。 这些功能是动态链接加载器的一部分。 您也必须链接动态链接器。 -ldl添加到链接标志。 另请参见系统的dlopen手册页

有点晚了,但是-最简单的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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM