gpt4 book ai didi

c++ - 如何解决 libmysqlclient_r.so 符号引用链接错误?

转载 作者:行者123 更新时间:2023-11-30 18:01:17 30 4
gpt4 key购买 nike

以下是 make 链接输出。它显示符号引用错误,即使我已经提供了 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)

尝试使用不同的标志,但仍然没有变化。请推荐

最佳答案

您的问题可能是您将对象和库传递给 ld (或通过 g++ld)的顺序很重要,并且您在依赖它的对象文件之前指定-lmysqlclient_r。您应该尝试将所有 -l 参数移至 *.o 之后的行尾,即将 makefile 步骤更改为

(取两点 - 实际上是 Mat 的评论观点:您已将库链接放入 LDFLAGS 变量中)

$(LIB) : $(OBJS)
$(LD) -o $(OBJS) $(LIB) $(LDFLAGS)

关于c++ - 如何解决 libmysqlclient_r.so 符号引用链接错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9886908/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com