为什么g ++不能在Ubuntu上链接由gcc创建的动态库

时间:2015-11-29 16:09:08

标签: c++ gcc sqlite g++ ubuntu-14.04

我为sqlite3 C库创建了一个C ++包装类,现在我想在我的项目中使用dinamically链接它。 这是我正在使用的Makefile

CC=gcc
PP=g++
LIBDIR=lib
CCFLAGS=-shared -fPIC -lpthread -ldl
PPFLAGS=-std=c++0x -Wall -O3 -L$(LIBDIR) -Wl,-rpath,./$(LIBDIR) -lsqlite3

INCDIR=src/include
HSRC=src/include/*
CPPSRC=src/*.cpp src/*/*.cpp

SQLITELIB=$(LIBDIR)/libsqlite3.so
SQLITESRC=src/db/sqlite3.c
SQLITEHSRC=src/include/db/sqlite3.h

OUT=server

$(OUT): $(CPPSRC) $(HSRC) $(SQLITELIB)
    $(PP) $(PPFLAGS) $(CPPSRC) -iquote $(INCDIR) -o $(OUT)

$(SQLITELIB): $(SQLITESRC) $(SQLITEHSRC) $(LIBDIR)
    $(CC) $(CCFLAGS) $(SQLITESRC) -o $(SQLITELIB)

$(LIBDIR):
    mkdir $(LIBDIR)

这是我得到的输出

mkdir lib
gcc -shared -fPIC -lpthread -ldl src/db/sqlite3.c -o lib/libsqlite3.so
g++ -std=c++0x -Wall -O3 -Llib -Wl,-rpath,./lib -lsqlite3 src/*.cpp src/*/*.cpp -iquote src/include -o server
/tmp/cchbxzB9.o: nella funzione "db::SQLiteDB::~SQLiteDB()":
SQLiteDB.cpp:(.text+0x172): riferimento non definito a "sqlite3_close"
SQLiteDB.cpp:(.text+0x19a): riferimento non definito a "sqlite3_errstr"
/tmp/cchbxzB9.o: nella funzione "db::SQLiteDB::close()":
SQLiteDB.cpp:(.text+0x1e2): riferimento non definito a "sqlite3_close"
SQLiteDB.cpp:(.text+0x20c): riferimento non definito a "sqlite3_errstr"
/tmp/cchbxzB9.o: nella funzione "db::SQLiteDB::prepare(std::string, sqlite3_stmt**)":
SQLiteDB.cpp:(.text+0x268): riferimento non definito a "sqlite3_prepare_v2"
SQLiteDB.cpp:(.text+0x28b): riferimento non definito a "sqlite3_errstr"
/tmp/cchbxzB9.o: nella funzione "db::SQLiteDB::bindBlob(sqlite3_stmt*, int, void*, int)":
SQLiteDB.cpp:(.text+0x2e5): riferimento non definito a "sqlite3_bind_blob"
SQLiteDB.cpp:(.text+0x308): riferimento non definito a "sqlite3_errstr"
collect2: error: ld returned 1 exit status
make: *** [server] Errore 1

我在Ubuntu 14.04上运行gcc版本4.8.4,我认为问题不在我的源代码中,因为我的同事正在使用gnt版本4.8.5在Gentoo上正确编译和链接它。 我错过了什么吗?

0 个答案:

没有答案