Bug #56809 Connector/C++ 1.1.0 links libstdc++
Submitted: 15 Sep 2010 20:55 Modified: 16 Sep 2010 9:09
Reporter: aron curzon Email Updates:
Status: Won't fix Impact on me:
None 
Category:Connector / C++ Severity:S3 (Non-critical)
Version:1.1.0 OS:Linux (Centos 5)
Assigned to: CPU Architecture:Any

[15 Sep 2010 20:55] aron curzon
Description:
Connector/C++ links against libstdc++.5
This is the same bug as http://bugs.mysql.com/bug.php?id=45128
linking against libstdc++.6 which is the system default causes the following error:

*** glibc detected *** ./cppapplication-01: free(): invalid pointer: 0x08cd4f58 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(+0x6b591)[0xac9591]
/lib/tls/i686/cmov/libc.so.6(+0x6cde8)[0xacade8]
/lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0xacdecd]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0x693741]
/usr/lib/libstdc++.so.6(_ZNSs4_Rep10_M_destroyERKSaIcE+0x1d)[0x66fc2d]
/usr/lib/libstdc++.so.6(_ZNSsD1Ev+0x4c)[0x6715dc]
./cppapplication-01[0x8049629]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0xa74bd6]
./cppapplication-01[0x8048fd1]
======= Memory map: ========
00110000-00134000 r-xp 00000000 08:05 3080667    /lib/tls/i686/cmov/libm-2.11.1.so
00134000-00135000 r--p 00023000 08:05 3080667    /lib/tls/i686/cmov/libm-2.11.1.so
00135000-00136000 rw-p 00024000 08:05 3080667    /lib/tls/i686/cmov/libm-2.11.1.so
00136000-00153000 r-xp 00000000 08:05 3063988    /lib/libgcc_s.so.1
00153000-00154000 r--p 0001c000 08:05 3063988    /lib/libgcc_s.so.1
00154000-00155000 rw-p 0001d000 08:05 3063988    /lib/libgcc_s.so.1
00155000-00205000 r-xp 00000000 08:05 7283646    /usr/lib/libstdc++.so.5.0.7
00205000-0020a000 rw-p 000af000 08:05 7283646    /usr/lib/libstdc++.so.5.0.7
0020a000-0020f000 rw-p 00000000 00:00 0 
0020f000-00219000 r-xp 00000000 08:05 3080677    /lib/tls/i686/cmov/libnss_files-2.11.1.so
00219000-0021a000 r--p 00009000 08:05 3080677    /lib/tls/i686/cmov/libnss_files-2.11.1.so
0021a000-0021b000 rw-p 0000a000 08:05 3080677    /lib/tls/i686/cmov/libnss_files-2.11.1.so
002f1000-002f2000 r-xp 00000000 00:00 0          [vdso]
002f2000-00518000 r-xp 00000000 08:05 7686038    /usr/lib/mysql-connector-c++-1.0.5/libmysqlcppconn.so.1.0.5
00518000-00556000 rw-p 00226000 08:05 7686038    /usr/lib/mysql-connector-c++-1.0.5/libmysqlcppconn.so.1.0.5
00556000-00557000 rw-p 00000000 00:00 0 
005d8000-006c1000 r-xp 00000000 08:05 7283335    /usr/lib/libstdc++.so.6.0.13
006c1000-006c2000 ---p 000e9000 08:05 7283335    /usr/lib/libstdc++.so.6.0.13
006c2000-006c6000 r--p 000e9000 08:05 7283335    /usr/lib/libstdc++.so.6.0.13
006c6000-006c7000 rw-p 000ed000 08:05 7283335    /usr/lib/libstdc++.so.6.0.13
006c7000-006ce000 rw-p 00000000 00:00 0 
0089d000-008b8000 r-xp 00000000 08:05 3063813    /lib/ld-2.11.1.so
008b8000-008b9000 r--p 0001a000 08:05 3063813    /lib/ld-2.11.1.so
008b9000-008ba000 rw-p 0001b000 08:05 3063813    /lib/ld-2.11.1.so
00944000-0094d000 r-xp 00000000 08:05 3080665    /lib/tls/i686/cmov/libcrypt-2.11.1.so
0094d000-0094e000 r--p 00008000 08:05 3080665    /lib/tls/i686/cmov/libcrypt-2.11.1.so
0094e000-0094f000 rw-p 00009000 08:05 3080665    /lib/tls/i686/cmov/libcrypt-2.11.1.so
0094f000-00976000 rw-p 00000000 00:00 0 
00a5e000-00bb1000 r-xp 00000000 08:05 3080662    /lib/tls/i686/cmov/libc-2.11.1.so
00bb1000-00bb2000 ---p 00153000 08:05 3080662    /lib/tls/i686/cmov/libc-2.11.1.so
00bb2000-00bb4000 r--p 00153000 08:05 3080662    /lib/tls/i686/cmov/libc-2.11.1.so
00bb4000-00bb5000 rw-p 00155000 08:05 3080662    /lib/tls/i686/cmov/libc-2.11.1.so
00bb5000-00bb8000 rw-p 00000000 00:00 0 
00cdd000-00cf0000 r-xp 00000000 08:05 3080672    /lib/tls/i686/cmov/libnsl-2.11.1.so
00cf0000-00cf1000 r--p 00012000 08:05 3080672    /lib/tls/i686/cmov/libnsl-2.11.1.so
00cf1000-00cf2000 rw-p 00013000 08:05 3080672    /lib/tls/i686/cmov/libnsl-2.11.1.so
00cf2000-00cf4000 rw-p 00000000 00:00 0 
00d5c000-00d71000 r-xp 00000000 08:05 3080690    /lib/tls/i686/cmov/libpthread-2.11.1.so
00d71000-00d72000 r--p 00014000 08:05 3080690    /lib/tls/i686/cmov/libpthread-2.11.1.so
00d72000-00d73000 rw-p 00015000 08:05 3080690    /lib/tls/i686/cmov/libpthread-2.11.1.so
00d73000-00d75000 rw-p 00000000 00:00 0 
08048000-0804d000 r-xp 00000000 08:01 6946898    /home/julien/NetBeansProjects/CppApplication-01/dist/Debug/GNU-Linux-x86/cppapplication-01
0804d000-0804e000 r--p 00004000 08:01 6946898    /home/julien/NetBeansProjects/CppApplication-01/dist/Debug/GNU-Linux-x86/cppapplication-01
0804e000-0804f000 rw-p 00005000 08:01 6946898    /home/julien/NetBeansProjects/CppApplication-01/dist/Debug/GNU-Linux-x86/cppapplication-01
08cd4000-08cf5000 rw-p 00000000 00:00 0          [heap]
b6e00000-b6e21000 rw-p 00000000 00:00 0 
b6e21000-b6f00000 ---p 00000000 00:00 0 
b6fea000-b6feb000 ---p 00000000 00:00 0 
b6feb000-b77ef000 rw-p 00000000 00:00 0 
b7807000-b780a000 rw-p 00000000 00:00 0 
bf9aa000-bf9bf000 rw-p 00000000 00:00 0          [stack]

How to repeat:
Source:
/*
examples/standalone_example_docs1.cpp
*/
	
/* Standard C++ includes */
#include <stdlib.h>
#include <iostream>
	
/*
  Include directly the different
  headers from cppconn/ and mysql_driver.h + mysql_util.h
  (and mysql_connection.h). This will reduce your build time!
*/
#include "mysql_connection.h"
	
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
	
using namespace std;
	
int main(void)
{
cout << endl;
cout << "Running 'SELECT 'Hello World!' AS _message'..." << endl;
	
try {
  sql::Driver *driver;
  sql::Connection *con;
  sql::Statement *stmt;
  sql::ResultSet *res;
	
  /* Create a connection */
  driver = get_driver_instance();
  con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
  /* Connect to the MySQL test database */
  con->setSchema("test");
	
  stmt = con->createStatement();
  res = stmt->executeQuery("SELECT 'Hello World!' AS _message");
  while (res->next()) {
    cout << "\t... MySQL replies: ";
    /* Access column data by alias or column name */
    cout << res->getString("_message") << endl;
    cout << "\t... MySQL says it again: ";
    /* Access column fata by numeric offset, 1 is the first column */
    cout << res->getString(1) << endl;
  }
  delete res;
  delete stmt;
  delete con;
	
} catch (sql::SQLException &e) {
  cout << "# ERR: SQLException in " << __FILE__;
  cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
  cout << "# ERR: " << e.what();
  cout << " (MySQL error code: " << e.getErrorCode();
  cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
	
cout << endl;
	
return EXIT_SUCCESS;
}

Compile:
g++ -DCPPCONN_PUBLIC_FUNC= -I"include" -I"include/cppconn" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"source/main.d" -MT"source/main.d" -o"object/main.o" "source/main.cpp"

Link:
g++ -L"${project_loc}/lib" -Xlinker -rpath ${project_loc}/lib/ -o"CppConnTest" ./object/main.o -lmysql -lmysqlcppconn -lmysqlclient -lmysqlclient_r
[15 Sep 2010 22:54] aron curzon
I should have mentioned this before but I was using the Linux-Generic versions of both Connector/C and Connector/C++. Using the Red Hat versions fixes the problem. The red hat version of Connector/C++ is compiled with gcc 4.1.2. The generic version doesn't say what it was compiled with but I suspect gcc 3.x
[16 Sep 2010 9:09] Ulf Wendel
Hi

Yes, we use GCC 3 on some systems. This is simply the default on many MySQL build systems. It won't change in the near future. Please either recompile or install compatiblity libraries.

Thanks,
Ulf