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

I know that this is more of a C question, but since I am trying to make it work with perl I think it qualifies. I am trying to compile a module to interact with mysql's myisam library. I am, however, having difficulties compiling it. I have managed to fake a test program to compile and the output from the Mysql make file is a follows
make mi_test1 source='mi_test1.c' object='mi_test1.o' libtool=no \ depfile='.deps/mi_test1.Po' tmpdepfile='.deps/mi_test1.TPo' \ depmode=gcc /bin/ksh ../depcomp \ gcc -DMAP_TO_USE_RAID -I. -I. -I.. -I./../include -I../include -O3 + -DDBUG_OFF -DHAVE_CURSES_H -I/idcom/tmp/mysql-4.0.12/include -DHAV +E_RWLOCK_T -c `test -f mi_test1.c || echo './'`mi_test1.c /bin/ksh ../libtool --mode=link gcc -O3 -DDBUG_OFF -DHAVE_CURSES_H +-I/idcom/tmp/mysql-4.0.12/include -DHAVE_RWLOCK_T -o mi_test1 mi_ +test1.o libmyisam.a ../mysys/libmysys.a ../dbug/libdbug.a ../strings +/libmystrings.a -lpthread -lthread -lcrypt -lgen -lsocket -lnsl -lm +-lpthread -lthread gcc -O3 -DDBUG_OFF -DHAVE_CURSES_H -I/idcom/tmp/mysql-4.0.12/include - +DHAVE_RWLOCK_T -o mi_test1 mi_test1.o libmyisam.a ../mysys/libmysys. +a ../dbug/libdbug.a ../strings/libmystrings.a -lpthread -lthread -lcr +ypt -lgen -lsocket -lnsl -lm -lpthread -lthread
The problem is... that doesn't look like it will play nicely with Makefile.PL, especially the libtool line which uses libtool distributed with the mysql source.

can anyone help me figure out how to get rework this into a more normal compile that I can work into Makefile.PL. I know C allright, but when it comes to linking libraries I am not very knowledgable.

                - Ant
                - Some of my best work - (1 2 3)

Replies are listed 'Best First'.
Re: Getting a C library to compile into a Perl module...
by tinypig (Beadle) on May 12, 2003 at 19:52 UTC
    suaveant,

    Why don't you start here: perlxstut, and bring your C code into this framework.

    Added:Also, h2xs accepts a parameter for specifying extra libraries.

    h2xs [-ACOPXacdfhkmx] [-F addflags] [-M fmask] [-n module_name] [-o tm +ask] [-p prefix] [-s subs] [-v version] [headerfile [extra_libraries] +] version: 1.21 -A Omit all autoloading facilities (implies -c). -C Omit creating the Changes file, add HISTORY heading to stub P +OD. -F Additional flags for C preprocessor (used with -x). -M Mask to select C functions/macros (default is select all). -O Allow overwriting of a pre-existing extension directory. -P Omit the stub POD section. -X Omit the XS portion (implies both -c and -f). -a Generate get/set accessors for struct and union members (used + with -x). -c Omit the constant() function and specialised AUTOLOAD from th +e XS file. -d Turn on debugging messages. -f Force creation of the extension even if the C header does not + exist. -h Display this help message -k Omit 'const' attribute on function arguments (used with -x). -m Generate tied variables for access to declared variables. -n Specify a name to use for the extension (recommended). -o Regular expression for "opaque" types. -p Specify a prefix which should be removed from the Perl functi +on names. -s Create subroutines for specified macros. -v Specify a version number for this extension. -x Autogenerate XSUBs using C::Scan. -b Specify a perl version to be backwards compatibile with extra_libraries are any libraries that might be needed for loading the extension, e.g. -lm would try to link in the math library.
    tinypig
      I am reading perlxstut, but I am not sure that is going to help... h2xs fails miserably with this library on its own. And I am using that framework, with the Makefile.PL. But if I am not mistaken, unless you know how to compile a test program or something in gcc, you can't really set up the Makefile info properly. I can't get a test file to compile, so I'm not even sure what linker options gcc needs...

                      - Ant
                      - Some of my best work - (1 2 3)

Additional Info
by suaveant (Parson) on May 12, 2003 at 16:57 UTC
    I have tried linking the two libraries I think I need in with -lmyisam and -lmysys, and even including them directly with lib/libmysys.a lib/libmyisam.a, but I just get
    gcc -I/idcom/tmp/mysql-4.0.12/include -Llib -lmyisam -lmysys lib/libmy +isam.a lib/libmysys.a test.c /var/tmp/cc7ojzF7.o: In function `main': /var/tmp/cc7ojzF7.o(.text+0xd4): undefined reference to `my_progname' /var/tmp/cc7ojzF7.o(.text+0xd8): undefined reference to `my_progname' /var/tmp/cc7ojzF7.o(.text+0xe8): undefined reference to `my_init' collect2: ld returned 1 exit status
    even though those functions are defined in mysys

                    - Ant
                    - Some of my best work - (1 2 3)

Re: Getting a C library to compile into a Perl module...
by Madams (Pilgrim) on May 12, 2003 at 21:34 UTC

    Are you using "ksh"?

    If so try changing your shell to "bash" or plain "sh". Sometimes Makefile.PL's makefiles tend to assume you are using "bash" or "sh".

    Actually, a lot of makefiles tend to have that assumption.
    _________________
    madams@scc.net
    (__) (\/) /-------\/ / | 666 || * ||----||
      no.. I am using bash... the ksh thing is just some weird thing mysql runs through. My real problem is I don't know how to compile this in just gcc, the only example is with libtool from mysql source distro.

                      - Ant
                      - Some of my best work - (1 2 3)

Re: Getting a C library to compile into a Perl module...
by Coplan (Pilgrim) on May 12, 2003 at 16:51 UTC
    For a minute there, I thought I was in the obfuscated code section.