christine has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
  I am trying to call a perl function that will use DBI from c++.   This is what I have included for that (in c++) as suggested by perl documentation:
#ifdef cplusplus #define EXTERN_C extern "C" #else #define EXTERN_C extern #endif extern "C" { # include "EXTERN.h" // from the Perl distribution # include "perl.h" } EXTERN_C { void boot_DynaLoader _((CV* cv)); void boot_DBI _((CV* cv)); void boot_DBD__mysql _((CV* cv)); } static void xs_init(){ newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__); newXS("DBI::bootstrap", boot_DBI, __FILE__); newXS("DBD::mysql::bootstrap", boot_DBD__mysql, __FILE__); }
but when I compile the c++ like this:
g++ -g -o dbChg dbWrapper.cc -Wno-deprecated `perl -MExtUtils::Embed - +e ccopts -e ldopts`
I got errors as the following:
/tmp/cccNMAhR.o: In function `void __iter_swap<char *, char *, char>(c +har *, char *, char *)': /usr/include/g++-3/stl_iterator.h(.text+0x29): undefined reference to +`boot_DBI' /usr/include/g++-3/stl_iterator.h(.text+0x43): undefined reference to +`boot_DBD__mysql' collect2: ld returned 1 exit status
It is gcc 2.96 with perl 5.6.1 under linux redhat.   Could you please give me some hint to make it work? Thank you so much.
  christine

janitored by ybiC: <code> tags around code block as per Monastery convention, fix minor format faux paus

Replies are listed 'Best First'.
Re: question about loading dbi when calling perl from c++
by tachyon (Chancellor) on Oct 02, 2003 at 03:05 UTC

    My docs (different to these docs ->perlman:perlembed) suggest this:

    static void xs_init (pTHX); EXTERN_C void boot_DynaLoader (pTHX_ CV* cv); EXTERN_C void boot_Socket (pTHX_ CV* cv); EXTERN_C void xs_init(pTHX) { char *file = __FILE__; /* DynaLoader is a special case */ newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); newXS("Socket::bootstrap", boot_Socket, file); }

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print