链接mariadb C连接器时未定义的引用

时间:2015-03-17 14:49:10

标签: c mariadb

我有一些(太多)小时试图让mariadb C连接器使用我自己的代码。 MySQL C连接器工作正常,但我决定迁移到mariadb。

最后我决定尝试一个最小的代码来检查问题是否与我的代码或环境有关,并且我得到了同样的错误。代码来自SO:Using MariaDB in C的这个问题。

#include <my_global.h>
#include <mysql.h>

int main(int argc, char **argv)
{  
  MYSQL *con = mysql_init(NULL);

  if (con == NULL) 
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      exit(1);
  }

  if (mysql_real_connect(con, "localhost", "root", "root_pswd", 
          NULL, 0, NULL, 0) == NULL) 
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      mysql_close(con);
      exit(1);
  }  

  if (mysql_query(con, "CREATE DATABASE testdb")) 
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      mysql_close(con);
      exit(1);
  }

  mysql_close(con);
  exit(0);
}

并尝试使用

进行编译
gcc -v -o mysql-test mysql-test.c $(mariadb_config --libs)

扩展到

gcc -v -o mysql-test mysql-test.c $(mariadb_config --libs)

我得到的输出是

Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.3 --enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --program-suffix=-4.3 --enable-linux-futex --without-system-libunwind --with-cpu=generic --build=x86_64-suse-linux
Thread model: posix
gcc version 4.3.4 [gcc-4_3-branch revision 152973] (SUSE Linux)
COLLECT_GCC_OPTIONS='-v' '-o' 'mysql-test' '-L/usr/local/lib/mariadb' '-mtune=generic'
 /usr/lib64/gcc/x86_64-suse-linux/4.3/cc1 -quiet -v mysql-test.c -quiet -dumpbase mysql-test.c -mtune=generic -auxbase mysql-test -version -o /tmp/ccISncmQ.s
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib64/gcc/x86_64-suse-linux/4.3/include
 /usr/lib64/gcc/x86_64-suse-linux/4.3/include-fixed
 /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/include
 /usr/include
End of search list.
GNU C (SUSE Linux) version 4.3.4 [gcc-4_3-branch revision 152973] (x86_64-suse-linux)
        compiled by GNU C version 4.3.4 [gcc-4_3-branch revision 152973], GMP version 4.2.3, MPFR version 2.3.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 91a878d77972b76d647d592fefc786fc
COLLECT_GCC_OPTIONS='-v' '-o' 'mysql-test' '-L/usr/local/lib/mariadb' '-mtune=generic'
 /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/as -V -Qy -o /tmp/ccD2nseu.o /tmp/ccISncmQ.s
GNU assembler version 2.20.0 (x86_64-suse-linux) using BFD version (GNU Binutils; SUSE Linux Enterprise 11) 2.20.0.20100122-0.7.9
COMPILER_PATH=/usr/lib64/gcc/x86_64-suse-linux/4.3/:/usr/lib64/gcc/x86_64-suse-linux/4.3/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/4.3/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/
LIBRARY_PATH=/usr/lib64/gcc/x86_64-suse-linux/4.3/:/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/lib/:/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'mysql-test' '-L/usr/local/lib/mariadb' '-mtune=generic'
 /usr/lib64/gcc/x86_64-suse-linux/4.3/collect2 --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o mysql-test /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-suse-linux/4.3/crtbegin.o -L/usr/local/lib/mariadb -L/usr/lib64/gcc/x86_64-suse-linux/4.3 -L/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.3/../../.. /tmp/ccD2nseu.o -lmariadb -lssl -lnsl -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib64/gcc/x86_64-suse-linux/4.3/crtend.o /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64/crtn.o
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `SSL_get_error@OPENSSL_1.0.0'
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `SSL_get_peer_certificate@OPENSSL_1.0.0'
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `SSL_CTX_load_verify_locations@OPENSSL_1.0.0'
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `SSL_set_ex_data@OPENSSL_1.0.0'
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `X509_STORE_CTX_get_error_depth@OPENSSL_1.0.0'
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `SSL_get_ex_data@OPENSSL_1.0.0'
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `SSL_write@OPENSSL_1.0.0'
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `SSL_clear@OPENSSL_1.0.0'
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `CRYPTO_THREADID_set_numeric@OPENSSL_1.0.0'
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `SSL_COMP_get_compression_methods@OPENSSL_1.0.0'
...

在库路径中安装了LibOpenSSL 1.0.0和库。我也必须安装libopenssl-devel。

在$ LD_LIBRARY_PATH,有一个到/lib64/libssl.so.1.0.0的libssl.so链接。如果我执行

nm -g /usr/lib64/libssl.so

我得到了

nm: /usr/lib64/libssl.so: no symbols

还安装了libopenssl 0.9.8

# rpm -qa | grep libopenssl
libopenssl0_9_8-0.9.8h-30.27.11
libopenssl-devel-1.0.0c-17.1
libopenssl0_9_8-32bit-0.9.8h-30.27.11
libopenssl1_0_0-1.0.0c-17.1

有任何线索吗?谢谢!

更新:输出ldd

# ldd /usr/local/lib/mariadb/libmariadb.so
/usr/local/lib/mariadb/libmariadb.so: /lib64/libcrypto.so.1.0.0: no version information available (required by /usr/local/lib/mariadb/libmariadb.so)
/usr/local/lib/mariadb/libmariadb.so: /lib64/libssl.so.1.0.0: no version information available (required by /usr/local/lib/mariadb/libmariadb.so)
/usr/local/lib/mariadb/libmariadb.so: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /usr/local/lib/mariadb/libmariadb.so)
        linux-vdso.so.1 =>  (0x00007fff2d90f000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f08bc078000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f08bbe73000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f08bbc1d000)
        libssl.so.1.0.0 => /lib64/libssl.so.1.0.0 (0x00007f08bb9c1000)
        libcrypto.so.1.0.0 => /lib64/libcrypto.so.1.0.0 (0x00007f08bb60f000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f08bb2b1000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f08bc521000)
        libz.so.1 => /lib64/libz.so.1 (0x00007f08bb099000)

找不到glicbc_2.14,但似乎libc.so.6应该没问题。在OpenSuse 11.4存储库中,glibc版本为glibc-2.11.3-12.15.1.x86_64.rpm

更新2:我成功地用

显示符号
objdump -tT /usr/lib64/libssl.so

并且符号在那里

更新3和解决方案(解决方法):

主要问题是libmariadb.so需要glibc 2.14,而在opensuse 11.4 glibc版本是2.11。从opensuse 12.1安装glibc 2.14涉及到我不能做的系统的严重升级。

我也试过使用2.0系列的连接器。它也失败了类似的消息。

接下来,我找了1.0系列。我读到以前连接器名为libmariadbclient,并记得我安装了一个libmariadbclient软件包,因此我将链接器标志更改为-lmariadbclient并且...... 它工作正常!

但是链接器并没有使用libmariadbclient包中的库,而是连接器包含的静态库(libmariadbclient.a)。因此静态链接连接器对我有用。

1 个答案:

答案 0 :(得分:1)

MariaDB Connector / C需要OpenSSL 1.0.1或更高版本。

请参阅Prerequisites For Building Connector/C From Source

请注意,OpenSSL版本&lt; 1.0.2是易受攻击的,可能是脆弱的。