一、錯誤現象
在linux編譯mysql代碼,出現如下錯誤:
/usr/lib64/mysql/libmysqlclient.a(client_plugin.c.o): In function `add_plugin':
/export/home/pb2/build/sb_0-9651683-1372794821.34/rpm/BUILD/mysql-5.6.12/mysql-5.6.12/sql-common/client_plugin.c:178: undefined reference to `dlclose'
/usr/lib64/mysql/libmysqlclient.a(client_plugin.c.o): In function `mysql_client_plugin_deinit':
/export/home/pb2/build/sb_0-9651683-1372794821.34/rpm/BUILD/mysql-5.6.12/mysql-5.6.12/sql-common/client_plugin.c:280: undefined reference to `dlclose'
/usr/lib64/mysql/libmysqlclient.a(client_plugin.c.o): In function `mysql_load_plugin_v':
/export/home/pb2/build/sb_0-9651683-1372794821.34/rpm/BUILD/mysql-5.6.12/mysql-5.6.12/sql-common/client_plugin.c:367: undefined reference to `dlopen'
/export/home/pb2/build/sb_0-9651683-1372794821.34/rpm/BUILD/mysql-5.6.12/mysql-5.6.12/sql-common/client_plugin.c:396: undefined reference to `dlsym'
/export/home/pb2/build/sb_0-9651683-1372794821.34/rpm/BUILD/mysql-5.6.12/mysql-5.6.12/sql-common/client_plugin.c:387: undefined reference to `dlerror'
/export/home/pb2/build/sb_0-9651683-1372794821.34/rpm/BUILD/mysql-5.6.12/mysql-5.6.12/sql-common/client_plugin.c:399: undefined reference to `dlclose'
collect2: ld returned 1 exit status
二、原因
要對使用dlopen的文件進行編譯時,需要加上 -ldl。
三、解決辦法
在Makefile中,加上-ldl。
LINK_OPTIONS := \
-lstdc++ \
-lrt \
-lpthread \
-ldl