Bug #112896 undefined reference to `mysql_stmt_bind_named_param'
Submitted: 31 Oct 2023 10:37 Modified: 31 Oct 2023 10:40
Reporter: Daniël van Eeden (OCA) Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S2 (Serious)
Version:8.2.0 OS:Any
Assigned to: CPU Architecture:Any

[31 Oct 2023 10:37] Daniël van Eeden
Description:
Following this doc:
https://dev.mysql.com/doc/c-api/8.2/en/mysql-stmt-bind-named-param.html

one needs to replace mysql_stmt_bind_param() with mysql_stmt_bind_named_param()

However with the 8.2.0 client libraries this results in a undefined reference.

How to repeat:
[dvaneeden@dve-carbon ~]$ cat mysql_bind_test.cc 
#include <mysql.h>
#include <vector>
#include <cstring>

int main() {
  MYSQL mysql;
  MYSQL_STMT *stmt;
  mysql_stmt_prepare(stmt, "SELECT POW(?,2) AS square", 26);
  int int_data = 4;  // unnamed input parameter
  int int_parentid = 1329494394;  // named input parameter ("traceparent")
  MYSQL_BIND all_params[2];
  memset(all_params, 0, sizeof(all_params));
  all_params[0].buffer_type = MYSQL_TYPE_LONG;
  all_params[0].buffer = (char *)&int_data;
  all_params[0].length = nullptr;
  all_params[0].is_null = nullptr;
  all_params[1].buffer_type = MYSQL_TYPE_LONG;
  all_params[1].buffer = (char *)&int_parentid;
  all_params[1].length = nullptr;
  all_params[1].is_null = nullptr;
  const char *names[2] = {nullptr, "traceparent"};
  int rc = mysql_stmt_bind_named_param(stmt, all_params,
           std::size(all_params), names);
}
[dvaneeden@dve-carbon ~]$ g++ -o mysql_bind_test -g $(mysql_config --cflags --libs) mysql_bind_test.cc 
/usr/bin/ld: /tmp/ccN2XLAh.o: in function `main':
/home/dvaneeden/mysql_bind_test.cc:22: undefined reference to `mysql_stmt_bind_named_param'
collect2: error: ld returned 1 exit status
[dvaneeden@dve-carbon ~]$ rpm -qf /usr/lib64/mysql/libmysqlclient.so.22
mysql-community-libs-8.2.0-10.fc38.x86_64
[dvaneeden@dve-carbon ~]$ objdump -T /usr/lib64/mysql/libmysqlclient.so.22 | grep -E 'mysql_stmt.*param'
000000000002ffa0 g    DF .text	000000000000000b  libmysqlclient_22.0 mysql_stmt_param_count
000000000002ffe0 g    DF .text	0000000000000338  libmysqlclient_22.0 mysql_stmt_bind_param
000000000002fe70 g    DF .text	0000000000000007  libmysqlclient_22.0 mysql_stmt_param_metadata
[31 Oct 2023 10:40] Daniël van Eeden
This is a duplicate of Bug #112893
[31 Oct 2023 10:46] MySQL Verification Team
Hello Daniël,

Thank you for the report and feedback.
As you rightly pointed out, this is duplicate of Bug #112893.

regards,
Umesh