0

following is the make linking output. it shows Symbol referencing errors, even though I have provided path for libmysqlclient_r.so

If I link it to libmysqlclient.so then it works fine. But as my program uses multithreading, I want to link 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

following is the make file

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)

Tried with different flags but still no change. Please suggest

user1145280
  • 371
  • 1
  • 2
  • 10
  • Try putting `LDFLAGS` (which is mis-named) after `OBJS` in the final link. – Mat Mar 27 '12 at 09:40
  • you mean like $(LD) -o $(LIB) $(OBJS) $(LDFLAGS) – user1145280 Mar 27 '12 at 10:04
  • I have tried as above it gives following error: `ld: warning: file /usr/lib/libmysqlclient_r.a(libmysql.o): wrong ELF class: ELFCLASS64 Undefined first referenced symbol in file same as above ld: fatal: Symbol referencing errors. No output written to ../../dbprocess/bin/dbprocess collect2: ld returned 1 exit status make: *** [../../dbprocess/bin/dbprocess] Error 1 ` – user1145280 Mar 28 '12 at 08:35
  • That means you're mixing 32bit binaries and 64bit ones. Don't do that. – Mat Mar 28 '12 at 08:55
  • if you see above error libmysqlclient_r.a(libmysql.o) , i dont want to link to .a but .so hence I have removed libmysqlclient_r.a and did make again but same error with .so
    ld: fatal: file /opt/mysql/mysql/lib/libmysqlclient_r.so: wrong ELF class: ELFCLASS64 ld: fatal: File processing errors. No output written to ../../dbprocess/bin/dbprocess collect2: ld returned 1 exit status make: *** [../../dbprocess/bin/dbprocess] Error 1
    – user1145280 Mar 28 '12 at 09:03
  • That means you're mixing 32bit binaries and 64bit ones. Don't do that. – Mat Mar 28 '12 at 09:04
  • I am working on solaris which is 64-bit, how do i check if .so file is compatible? – user1145280 Mar 28 '12 at 09:06
  • Try `file libmysqlclient_r.so` - it'll tell you if it's 32 or 64-bit. Note from your error above you're actually statically linking this at the moment. – Rup Mar 28 '12 at 10:06
  • following is the output `bash-3.00# file /opt/mysql/mysql/lib/libmysqlclient_r.so /opt/mysql/mysql/lib/libmysqlclient_r.so: ELF 64-bit MSB dynamic lib SPARCV9 Version 1, dynamically linked, not stripped` as it shows that libmysqlclient_r.so is 64-bit then why wrong ELF class: ELFCLASS64 error is coming? – user1145280 Mar 28 '12 at 10:50
  • any comments on above issue..? – user1145280 Mar 29 '12 at 06:41
  • this issue is solved after linking 32-bit so file. thanks a lot – user1145280 Apr 17 '12 at 11:33

1 Answers1

0

Your problem could be that the order you pass objects and libraries to ld (or ld via g++) is significant and you're specifying -lmysqlclient_r before the object files that depend on it. You should try moving all of the -l parameters to the end of the line after *.o, i.e. change your makefile step to

(take two - actually Mat's point from comments: you've put the library links in the LDFLAGS variable)

$(LIB) : $(OBJS)
$(LD) -o $(OBJS) $(LIB) $(LDFLAGS)
Rup
  • 33,765
  • 9
  • 83
  • 112
  • I have tried make with above changes. now I didn't get any linking error like Undefined symbol but following error.
    g++: ../../dbprocess/bin/dbprocess: No such file or directory make: *** [../../dbprocess/bin/dbprocess] Error 1
    – user1145280 Mar 28 '12 at 08:21
  • D'oh, sorry, I'd missed the point that Mat had spotted - you're using using LDFLAGS to actually link the libraries not actually as general linker flags. It's LDFLAGS that needs to go last as he suggests, not LIB (which is your output binary name?!). – Rup Mar 28 '12 at 10:04