Conflict between perl DBI & libmysqlclient

rbrown46_at_gmail.com
Date: 01/18/05


Date: 17 Jan 2005 20:36:26 -0800

I'm developing a C program that embeds perl code for certain things
(using perl_run, perl_parse, perl_destuct, etc.). I ran into a problem
because libmysqlclient is getting used two times: in perl through DBI
and in C, directly. I need to use libmysqlclient in C and I need to
have perl call libmysqlclient through DBI. Because of this conflict,
the program crashes. Below are two source files (perl & C) that will
illustrate the problem. Through I backtrace in gdb I found that the
crash usually occurs while freeing a variable in perl_destruct().
Compile exampleC.c with "gcc -o example exampleC.c `perl
-MExtUtils::Embed -e ccopts -e ldopts`", then run example with
"./example examplePerl.pl" and experience no segmentation faults.
Compile with "gcc -o example exampleC.c `perl -MExtUtils::Embed -e
ccopts -e ldopts` -lmysqlclient", run it with the same command, and
experience a crash.

Any help is greatly appreciated!
Ryan

examplePerl.pl:
#!/usr/bin/perl

use DBI;
use Finance::Quote;

print "Perl code is running";

$dbh = DBI->connect("dbi:mysql:dbname=noname", "user1", "pass1")
or die "Cannot connect to database: $DBI::errstr";

exampleC.c:
#include <EXTERN.h>
#include <perl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>

EXTERN_C void xs_init (pTHX);

EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);

EXTERN_C void
xs_init(pTHX)
{
char *file = __FILE__;
dXSUB_SYS;

/* DynaLoader is a special case */
newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
}

main(int argc, char **argv, char **env) {
PerlInterpreter *my_perl;

my_perl = perl_alloc();
perl_construct(my_perl);

perl_parse(my_perl, xs_init, argc, argv, env);
perl_run(my_perl);
perl_destruct(my_perl);
   perl_free(my_perl);
}



Relevant Pages

  • RE: perl DBI oracle and error ORA 06502
    ... procedure, schema, some data and the exact perl code that calls it. ... I would also need the name of and version your OS, perl, DBI, ... DBD::Oracle, The Oracle client you are running and the Oracle DB ... The problem shows in the perl code. ...
    (perl.dbi.users)
  • Re: Perl 6 DBI API ideas
    ... Though I didn't raise my hand when you asked for people to contribute to a DBI module for Perl 6, I've had some ideas that I thought about sharing. ... I would also love to see some standardization on the driver names ("mysql" when it's normally written ... DBI is supposed to be query language agnostic, even if SQL is the most commonly used group of languages, and if a user can declare this explicitly, it saves the driver from having to guess what they were given, which might be ambiguous. ...
    (perl.dbi.users)
  • Problem of DBI build
    ... I installed Oracle Application Server 4.0.8.2 included perl module. ... I need to installe DBI and DBD::Oracle module. ... You can install them any time after installing the DBI. ... line 318: error 1705: Function prototypes are an ANSI feature. ...
    (perl.dbi.users)
  • Problem of DBI build
    ... I installed Oracle Application Server 4.0.8.2 included perl module. ... I need to installe DBI and DBD::Oracle module. ... You can install them any time after installing the DBI. ... line 318: error 1705: Function prototypes are an ANSI feature. ...
    (perl.dbi.users)
  • Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
    ... T> expected a mature library like DBI to behave like this. ... I learned plenty about the perl side of things from her posts. ... closely represent the SQL idea of a null. ... trivially easy to perform bulk loads using the DB's particular ...
    (comp.lang.perl.misc)