以下是make链接输出。 它显示了Symbol引用错误,即使我已经为libmysqlclient_r.so
提供了路径如果我将它链接到libmysqlclient.so,那么它可以正常工作。但是由于我的程序使用多线程,我想链接libmysqlclient_r.so
g++ -L/usr/local/lib -L/lib/64 -L/opt/mysql/mysql/lib -L../../dependencies/glog/lib -L../../dependencies/libevent/lib -L../../dependencies/json/jsoncpp/lib -ljson-gcc-3.4.3_libmt -levent -lglog -lz -lmysqlclient_r -lpthread -lnsl -lumem -lmysys -lmystrings -o ../../dbprocess/bin/dbprocess dbprocess.o sessionlookupcsidrequest.o sessionlookupipv4request.o ../dbframework/connectionpool.o ../dbframework/connectionproxy.o ../dbframework/dbconnection.o ../framework/rpcmethod.o ../framework/rpcmethoddispatcher.o ../framework/rpcmethodfactory.o ../framework/jsonmethod.o ../framework/libeventmethoddispatcher.o ../framework/tobject.o ../framework/acceptor.o ../framework/configuefile.o ../framework/connmethoddata.o
Undefined first referenced
symbol in file
mysql_error ../dbframework/dbconnection.o
mysql_close ../dbframework/dbconnection.o
mysql_stmt_store_result sessionlookupcsidrequest.o
mysql_stmt_close ../dbframework/dbconnection.o
mysql_stmt_fetch sessionlookupcsidrequest.o
mysql_stmt_error sessionlookupcsidrequest.o
mysql_options ../dbframework/dbconnection.o
mysql_stmt_free_result sessionlookupcsidrequest.o
mysql_stmt_bind_result sessionlookupcsidrequest.o
mysql_stmt_num_rows sessionlookupcsidrequest.o
mysql_stmt_prepare ../dbframework/dbconnection.o
mysql_ping ../dbframework/dbconnection.o
mysql_init ../dbframework/dbconnection.o
mysql_stmt_bind_param sessionlookupcsidrequest.o
mysql_real_connect ../dbframework/dbconnection.o
mysql_stmt_execute sessionlookupcsidrequest.o
mysql_stmt_init ../dbframework/dbconnection.o
ld: fatal: Symbol referencing errors. No output written to ../../dbprocess/bin/dbprocess
collect2: ld returned 1 exit status
make: *** [../../dbprocess/bin/dbprocess] Error 1
以下是make文件
CPP = g++
LD = $(CPP)
OBJS = dbprocess.o sessionlookupcsidrequest.o sessionlookupipv4request.o ../dbframework/connectionpool.o ../dbframework/connectionproxy.o ../dbframework/dbconnection.o ../framework/rpcmethod.o ../framework/rpcmethoddispatcher.o ../framework/rpcmethodfactory.o ../framework/jsonmethod.o ../framework/libeventmethoddispatcher.o ../framework/tobject.o ../framework/acceptor.o ../framework/configuefile.o ../framework/connmethoddata.o
CPPFLAGS = -g $(INCFLAGS) -c -Wall -pthreads
LDFLAGS = -L/usr/local/lib -L/lib/64 -L/opt/mysql/mysql/lib/ -L../../dependencies/mysql/lib/solaris -L../../dependencies/glog/lib -L../../dependencies/libevent/lib -L../../dependencies/json/jsoncpp/lib -ljson-gcc-3.4.3_libmt -levent -lglog -lz -lmysqlclient_r -lpthread -lnsl -lumem -lmysys -lmystrings
LIB = ../../dbprocess/bin/dbprocess
INCFLAGS = -I../includes -I/opt/mysql/mysql/include -I../../dependencies/glog/include -I../../dependencies/json/jsoncpp/include -I../../dependencies/libevent/include
all : $(LIB)
$(LIB) : $(OBJS)
$(LD) $(LDFLAGS) -o $(LIB) $(OBJS)
%.o: ../%.cpp
$(CPP) $(CPPFLAGS) $<
clean :
rm -r -f $(LIB) $(OBJS)
尝试了不同的旗帜,但仍然没有变化。请建议
答案 0 :(得分:0)
您的问题可能是您将对象和库传递到ld
(或ld
通过g++
)的顺序非常重要,并且您在对象之前指定-lmysqlclient_r
依赖于它的文件。您应该尝试将所有-l
参数移到*.o
之后的行尾,即将您的makefile步骤更改为
(取两个 - 实际上是Mat的评论点:您已将库链接放在LDFLAGS变量中)
$(LIB) : $(OBJS)
$(LD) -o $(OBJS) $(LIB) $(LDFLAGS)