Search code examples
c++compilationmissing-symbols

DSO missing from command line when compiling


I have seen here several posts with similar questions and tried many suggestions but still, I haven't found a way around my problem. I use for my work some cpp codes that I have to slightly change according to my needs. They have their own makefile with the same structure. Those files use the same list of libraries and while I can compile some of them, for others the compilation is not successful. Specifically, I'm getting the following error:

 /usr/bin/ld: fill_worldqual_load.o: undefined reference to symbol 'mysql_free_result@@libmysqlclient_18'//usr/lib64/mysql/libmysqlclient.so.18: error adding symbols: DSO missing from command line

The makefile is this:

CC         = g++ -Wall -Wno-unused-but-set-variable
MAKE       = make -f makefile
APPNAME    = fill_worldqual_load
OBJECTS    = fill_worldqual_load.o ../general_function/timestring.o \
../general_function/country.o \
../general_function/general_functions.o \
../options/options.o options_fill_wq_load.o
CCOPTS     = -c
OPTIMIZE   = -O3

INCDIROPTS  = -L/usr/local/lib/libmysqlpp.so -I/usr/include/mysql -L/usr/lib64/mysql/libmysqlclient.so  -I/usr/local/include/mysql++ -I../general_function -I../options 
LNKLIB      = -lmysqlpp

$(APPNAME): $(OBJECTS)
    $(CC) $(INCDIROPTS) $(LNKOPTS) -o $(APPNAME) $(OBJECTS) $(LNKLIB) 

.cpp.o: 
    $(CC) -c $(INCDIROPTS) $(DEBUG) -o $*.o $*.cpp 

all:    clean 
    @$(MAKE) $(APPNAME)
    echo all: make complete

I have succesfully compiled similar codes with the same list of libraries and the same makefile structure. After calling ldd for one of those programs I get:

libmysqlpp.so.3 => /usr/local/lib/libmysqlpp.so.3
libstdc++.so.6 => /usr/lib64/libstdc++.so.6
libm.so.6 => /usr/lib64/libm.so.6
libgcc_s.so.1 => /usr/lib64/libgcc_s.so.1
libc.so.6 => /usr/lib64/libc.so.6
libmysqlclient.so.18 => //usr/lib64/mysql/libmysqlclient.so.18
/lib64/ld-linux-x86-64.so.2 (0x00002aaffda12000)
libpthread.so.0 => /usr/lib64/libpthread.so.0 (0x00002aaffef79000)
libz.so.1 => /usr/lib64/libz.so.1 (0x00002aafff195000)
libssl.so.10 => /usr/lib64/libssl.so.10 (0x00002aafff3ab000)
libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00002aafff61d000)
libdl.so.2 => /usr/lib64/libdl.so.2 (0x00002aafffa7f000)
libgssapi_krb5.so.2 => /usr/lib64/libgssapi_krb5.so.2 (0x00002aafffc83000)
libkrb5.so.3 => /usr/lib64/libkrb5.so.3 (0x00002aafffed0000)
libcom_err.so.2 => /usr/lib64/libcom_err.so.2 (0x00002ab0001b9000)
libk5crypto.so.3 => /usr/lib64/libk5crypto.so.3 (0x00002ab0003bd000)
libkrb5support.so.0 => /usr/lib64/libkrb5support.so.0 (0x00002ab0005f0000)
libkeyutils.so.1 => /usr/lib64/libkeyutils.so.1 (0x00002ab000800000)
libresolv.so.2 => /usr/lib64/libresolv.so.2 (0x00002ab000a04000)
libselinux.so.1 => /usr/lib64/libselinux.so.1 (0x00002ab000c1d000)
libpcre.so.1 => /usr/lib64/libpcre.so.1 (0x00002ab000e44000)

If I understand well, this program succesfully linked libmysqlclient.so.18 but the program I first mentioned did not. I don't understand why. I really appreciate any hint!


Solution

  • The INCDIROPTS field is incorrect. In Makefiles, library locations are specified with -L and the actual library names are linked with -l.

    Specify the mysql library with -L/usr/lib64/mysql in INCDIROPTS, and then link it with -lmysqlclient in LNKLIB.