我花了很多时间试图使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,有一个libssl.so链接到/lib64/libssl.so.1.0.0。如果我执行

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)。因此,静态链接连接器对我有用。

最佳答案

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

Prerequisites For Building Connector/C From Source

另请注意,版本低于1.0.2的OpenSSL版本已被淘汰,可能很容易受到攻击。

09-05 15:57