[CONC-492] Can't compile a client plugin with libmariadb-dev-compat on ubuntu 20.04 Created: 2020-09-04  Updated: 2020-09-06  Resolved: 2020-09-05

Status: Closed
Project: MariaDB Connector/C
Component/s: None
Affects Version/s: 3.1.9
Fix Version/s: 3.1.10

Type: Bug Priority: Trivial
Reporter: Miguel Sacristan Izcue Assignee: Georg Richter
Resolution: Fixed Votes: 0
Labels: None
Environment:

Ubuntu 20.04



 Description   

I can't seem to compile a very simple c++ file with the `mysql/client_plugin.h` file included.

Here is a sample file to reproduce

#include <mysql.h>
extern "C" {
#include <mysql/client_plugin.h>
}
 
int main()
{
        st_mysql_client_plugin_AUTHENTICATION example{
                .type = MYSQL_CLIENT_AUTHENTICATION_PLUGIN,
                .interface_version = MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION,
                .name = "example",
                .author = "tete17",
                .desc = "Bugy",
                .version = {0, 0, 1},
                .mysql_api = nullptr,
                .init = nullptr,
                .deinit = nullptr,
                .options = nullptr,
                .authenticate_user = nullptr
        };
        return 0;
}

My command line is `g++ main.cpp -I /usr/include/mysql -lmysql`. I am getting this error.

In file included from /usr/include/mysql/mysql/client_plugin.h:113,
                 from main.cpp:3:
/usr/include/mysql/ma_pvio.h:63:34: error: 'uchar' has not been declared
   63 |   void (*callback)(MYSQL *mysql, uchar *buffer, size_t size);
      |                                  ^~~~~
/usr/include/mysql/ma_pvio.h:70:3: error: 'uchar' does not name a type; did you mean 'u_char'?
   70 |   uchar *cache;
      |   ^~~~~
      |   u_char
/usr/include/mysql/ma_pvio.h:71:3: error: 'uchar' does not name a type; did you mean 'u_char'?
   71 |   uchar *cache_pos;
      |   ^~~~~
      |   u_char
/usr/include/mysql/ma_pvio.h:80:63: error: 'uchar' does not name a type; did you mean 'u_char'?
   80 |   void (*callback)(MARIADB_PVIO *pvio, my_bool is_read, const uchar *buffer, size_t length);
      |                                                               ^~~~~
      |                                                               u_char
/usr/include/mysql/ma_pvio.h:96:39: error: 'uchar' has not been declared
   96 |   ssize_t (*read)(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
      |                                       ^~~~~
/usr/include/mysql/ma_pvio.h:97:45: error: 'uchar' has not been declared
   97 |   ssize_t (*async_read)(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
      |                                             ^~~~~
/usr/include/mysql/ma_pvio.h:98:46: error: 'uchar' does not name a type; did you mean 'u_char'?
   98 |   ssize_t (*write)(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
      |                                              ^~~~~
      |                                              u_char
/usr/include/mysql/ma_pvio.h:99:52: error: 'uchar' does not name a type; did you mean 'u_char'?
   99 |   ssize_t (*async_write)(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
      |                                                    ^~~~~
      |                                                    u_char
/usr/include/mysql/ma_pvio.h:116:48: error: 'uchar' has not been declared
  116 | ssize_t ma_pvio_cache_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
      |                                                ^~~~~
/usr/include/mysql/ma_pvio.h:117:42: error: 'uchar' has not been declared
  117 | ssize_t ma_pvio_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
      |                                          ^~~~~
/usr/include/mysql/ma_pvio.h:118:49: error: 'uchar' does not name a type; did you mean 'u_char'?
  118 | ssize_t ma_pvio_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
      |                                                 ^~~~~
      |                                                 u_char
main.cpp: In function 'int main()':
main.cpp:20:2: error: 'st_mysql_client_plugin_AUTHENTICATION' has no non-static data member named 'mysql_api'
   20 |  };
      |  ^

I think the last error is due to a bug in gcc where it doesn't properly expand the macro `MYSQL_CLIENT_PLUGIN_HEADER`, but `uchar` is not defined anywhere except `server/my_global.h` which I think I am not supposed to include but I am not sure. I have a feeling this is related to the fact that now all my `my_*.h` files are empty except for a compiler warning. I have notice this only after upgrading from ubuntu 18.04 to ubuntu 20.04.

I would appreciate any help please. If I have made a mistake along the way please let me know as well if more info is needed.

Thanks in advance



 Comments   
Comment by Georg Richter [ 2020-09-05 ]

If a plugin is build outside of the source tree, we can't include ma_global.h (not delivered in binary package) - instead of we need to add a

typedef unsigned char uchar;

to the pvio header file.

As a workaround you could also add this typedef in your code before including mariadb include files.

Comment by Georg Richter [ 2020-09-05 ]

Fixed in rev. 822233846243008060e2a683ca5900351977a1fe

Comment by Miguel Sacristan Izcue [ 2020-09-05 ]

Thanks a lot @Georg Richter I am impressed by the turnaround time.

I applied the work around already and worked as expected thansk.

I still have a couple of question I was hoping you could maybe help me find the answers to.

1. Where can I find info about why the files my_*.h where sort of removed? Was this something coming from mysql upstream or a mariadb decision?
2. When can I expect the ubuntu package to be updated or do we only get security patches?
3. Why is the macro MYSQL_CLIENT_PLUGIN_HEADER defined in the mysql.h file with a reference to a void* mariadb_api instead of a void* mysql_api? The mysql definition in the client_plugin.h header can't kick in because it was previously defined.

Let me know if I should make this questions through another channel

Comment by Georg Richter [ 2020-09-06 ]

1) Long time ago we removed all internal files, which weren't part of the API.
2) I can't tell you about exact release date of C/C 3.1.10 - platform packages will be available from our [download site|https://downloads.mariadb.com/Connectors/c/ - It will be also included in next MariaDB 10.5 release
3) is fixed already

Generated at Thu Feb 08 03:05:42 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.