Bug #82595 my_charset_utf8_general_ci missing in the libmysqlclient.so
Submitted: 16 Aug 2016 9:27 Modified: 18 Aug 2016 8:54
Reporter: dennis gao Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:5.7 OS:Any
Assigned to: CPU Architecture:Any

[16 Aug 2016 9:27] dennis gao
Description:
my_charset_utf8_general_ci is missing in the libmysqlclient.so.

The client program will get the following error during the compile:

undefined reference to `my_charset_utf8_general_ci'

How to repeat:
The test program:

---------------------------------
mytest.c
---------------------------------
#include <string.h>

#include "m_ctype.h"

int main() {
  char str1[] = "opu7EuA-fC8-ZW3mfo9hHUz43Agg";
  char str2[] = "opu7EuA-HzXxRl58Z8yGdOeTNi0E";
  char str3[] = "opu7EuA-RW1nVvcGFjKPHH04N-1c";
  char str4[] = "opu7EuA-_9Xs6df2tbwIBxC26sBM";
  char str5[] = "opu7EuA0OfNdEKfXqNkthrTgRgO8";

  char *p[] = {str1, str2, str3, str4, str5};
  int i, j;
  int len = sizeof(p) / sizeof(char*);

  for (i = 0; i < len ; i++) {
    for (j =i+1; j < len; j++) {
      int ret =
        my_charset_utf8_general_ci.coll->strnncollsp(&my_charset_utf8_general_ci,
            p[i], strlen(p[i]),
            p[j], strlen(p[j]),
            0);
      if (ret  == 1) {
        char *s = p[i];
        p[i] = p[j];
        p[j] = s;
      }
    }
  }

  printf("Sort result with asc order :\n");
  for (i = 0; i < len; i++) {
    printf("%s\n", p[i]);
  }
  return 0;
}

----------------------------------------------
build.sh
----------------------------------------------
#!/bin/bash
myinclude=`mysql_config --include`
mylib=`mysql_config --libs`

gcc -g -o mytest mytest.c  $myinclude $mylib

use build.sh to compile.
Above program can compile for mysql5.5, mysql5.6, but fail for mysql5.7, and
report the error:
undefined reference to `my_charset_utf8_general_ci'

But if I adjust the build.sh to use the libmysqlclient.a, it works.

----------------------------------------------
build-modify.sh
----------------------------------------------
#!/bin/bash
myinclude=`mysql_config --include`

gcc -g -o mytest mytest.c /usr/local/mysql/lib/libmysqlclient.a $myinclude
[18 Aug 2016 7:04] Chiranjeevi Battula
Hello dennis gao,

Thank you for the bug report.
As per my internal discussion with Developers, this is an expected behavior in 5.7 and onwards that some C API functions are now hidden in C client library.

Thanks,
Chiranjeevi.
[18 Aug 2016 8:54] dennis gao
Hello Chiranjeevi,

Thanks for the response, where I can find the document about this hidden c api?

I am now working on sorting the result from multiple backend mysql(sharding).
I need to use this kind of mysql string compare api to ensure I sort the result the same as mysql does.

whether these c api will still in the libmysqlclient.a in the future?

dennis
[24 Aug 2016 12:31] Erlend Dahl
For some background on this topic:

http://mysqlserverteam.com/the-client-library-part-1-the-api-the-whole-api-and-nothing-but...