编译时命令行缺少 DSO
DSO missing from command line when compiling
我在这里看到了几篇有类似问题的帖子,并尝试了很多建议,但我仍然没有找到解决问题的方法。
我在我的工作中使用了一些 cpp 代码,我必须根据我的需要稍微改变它们。他们有自己的具有相同结构的makefile。这些文件使用相同的库列表,虽然我可以编译其中一些,但对于其他文件,编译不成功。具体来说,我收到以下错误:
/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
makefile 是这样的:
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
我已经使用相同的库列表和相同的 makefile 结构成功编译了类似的代码。在为其中一个程序调用 ldd 后,我得到:
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)
如果我没看错的话,这个程序链接成功了 libmysqlclient.so.18 但我第一次提到的那个程序没有。我不明白为什么。我真的很感激任何提示!
INCDIROPTS
字段不正确。在 Makefile 中,library locations are specified with -L
and the actual library names are linked with -l
.
在INCDIROPTS
中用-L/usr/lib64/mysql
指定mysql库,然后在LNKLIB
中用-lmysqlclient
link。
我在这里看到了几篇有类似问题的帖子,并尝试了很多建议,但我仍然没有找到解决问题的方法。 我在我的工作中使用了一些 cpp 代码,我必须根据我的需要稍微改变它们。他们有自己的具有相同结构的makefile。这些文件使用相同的库列表,虽然我可以编译其中一些,但对于其他文件,编译不成功。具体来说,我收到以下错误:
/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
makefile 是这样的:
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
我已经使用相同的库列表和相同的 makefile 结构成功编译了类似的代码。在为其中一个程序调用 ldd 后,我得到:
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)
如果我没看错的话,这个程序链接成功了 libmysqlclient.so.18 但我第一次提到的那个程序没有。我不明白为什么。我真的很感激任何提示!
INCDIROPTS
字段不正确。在 Makefile 中,library locations are specified with -L
and the actual library names are linked with -l
.
在INCDIROPTS
中用-L/usr/lib64/mysql
指定mysql库,然后在LNKLIB
中用-lmysqlclient
link。