MySQL C API Example

  • Can anybody out there using MySQL build this example?  The Makefile and
    client1.c files are given below.  Here is what I get when I try to build it.

    [max:samp_db/capi/client1] sam% make
    cc -o client1 client1.o -L/usr/local/lib/mysql  -lmysqlclient -dylib
    /usr/bin/ld: table of contents for archive:
    /usr/local/lib/mysql/libmysqlclient.a is out of date; rerun ranlib(1) (can't
    load from it)
    make: *** [client1] Error 1

    Regards,

    Sam Daniel
    Motorola
    480-441-7431

    -----------------------------------------------------------------------------
    CC = cc
    #CC = gcc
    INCLUDES = -I/usr/local/include/mysql
    LIBS = -L/usr/local/lib/mysql  -lmysqlclient -dylib
    #LIBS = -L/usr/local/lib/mysql -lmysqlclient -lm #-lsocket -lnsl

    PROG = client1

    all:: $(PROG)

    .c.o:
    $(CC) -c $(INCLUDES) $<

    $(PROG): $(PROG).o
    $(CC) -o $@ $(PROG).o $(LIBS)

    clean::
    rm -f $(PROG).o $(PROG)

    -----------------------------------------------------------------------------
    /* client1.c */

    #include <stdio.h>
    #include <mysql.h>

    #define def_host_name    NULL /* host to connect to (default = localhost) */
    #define def_user_name    NULL /* user name (default = your login name) */
    #define def_password    NULL /* password (default = none) */
    #define def_db_name    NULL /* database to use (default = none) */

    MYSQL    *conn;              /* pointer to connection handler */

    int
    main (int argc, char *argv[])
    {
        conn = mysql_init (NULL);
        mysql_real_connect ( conn,          /* pointer to connection handler */
                            def_host_name,  /* host to connect to */
                            def_user_name,  /* user name */
                            def_password,  /* password */
                            def_db_name,     /* database to use */
                            0,              /* port (use default) */
                            NULL,          /* socket (use default) */
                            0);            /* flags (none) */
    mysql_close (conn);
    exit (0);
    }
    -----------------------------------------------------------------------------
  • >
    > Can anybody out there using MySQL build this example?  The Makefile and
    > client1.c files are given below.  Here is what I get when I try to build it.
    >
    > [max:samp_db/capi/client1] sam% make
    > cc -o client1 client1.o -L/usr/local/lib/mysql  -lmysqlclient -dylib
    > /usr/bin/ld: table of contents for archive:
    > /usr/local/lib/mysql/libmysqlclient.a is out of date; rerun ranlib(1) (can't
    > load from it)
    > make: *** [client1] Error 1

    MacOS X is very flacky about the table of contents for static libraries,
    just run ranlib /usr/local/lib/mysql/libmysqlclient.a, if you have root
    premision.
    Thanks,
    Andrew Pinski

    >
    > Regards,
    >
    > Sam Daniel
    > Motorola
    > 480-441-7431
    >
    > -----------------------------------------------------------------------------
    > CC = cc
    > #CC = gcc
    > INCLUDES = -I/usr/local/include/mysql
    > LIBS = -L/usr/local/lib/mysql  -lmysqlclient -dylib
    > #LIBS = -L/usr/local/lib/mysql -lmysqlclient -lm #-lsocket -lnsl
    >
    > PROG = client1
    >
    > all:: $(PROG)
    >
    > .c.o:
    > $(CC) -c $(INCLUDES) $<
    >
    > $(PROG): $(PROG).o
    > $(CC) -o $@ $(PROG).o $(LIBS)
    >
    > clean::
    > rm -f $(PROG).o $(PROG)
    >
    > -----------------------------------------------------------------------------
    > /* client1.c */
    >
    > #include <stdio.h>
    > #include <mysql.h>
    >
    > #define def_host_name    NULL /* host to connect to (default = localhost) */
    > #define def_user_name    NULL /* user name (default = your login name) */
    > #define def_password    NULL /* password (default = none) */
    > #define def_db_name    NULL /* database to use (default = none) */
    >
    > MYSQL    *conn;              /* pointer to connection handler */
    >
    > int
    > main (int argc, char *argv[])
    > {
    > conn = mysql_init (NULL);
    > mysql_real_connect ( conn,          /* pointer to connection handler */
    > def_host_name,  /* host to connect to */
    > def_user_name,  /* user name */
    > def_password,  /* password */
    > def_db_name,     /* database to use */
    > 0,              /* port (use default) */
    > NULL,          /* socket (use default) */
    > 0);            /* flags (none) */
    > mysql_close (conn);
    > exit (0);
    > }
    > -----------------------------------------------------------------------------
    > _______________________________________________
    > MacOSX-dev mailing list
    > <MacOSX-dev...>
    > http://www.omnigroup.com/mailman/listinfo/macosx-dev
    >
    >
  • Hi Andrew and Scott,

    I followed your advice and ran ranlib.  Here is what I got:

    [max:samp_db/capi/client1] sam% make
    cc -o client1 client1.o -L/usr/local/lib/mysql  -lmysqlclient -dylib
    /usr/bin/ld: Undefined symbols:
    _compress
    _uncompress
    make: *** [client1] Error 1

    I suspect that I have not included needed libraries.  What do you think?

    Sam Daniel
    Motorola
    480-441-7431

    Begin forwarded message:

    Date: Tue, 6 Mar 2001 18:04:56 -0800
    Reply-To: <samis...>
    X-Mailer: Apple Mail (2.343)
    From: Sam Daniel <samis...>
    To: <sam...>
    Subject: MySQL C API client1 example follow-on 1

    [max:samp_db/capi/client1] sam% make
    cc -o client1 client1.o -L/usr/local/lib/mysql  -lmysqlclient -dylib
    /usr/bin/ld: Undefined symbols:
    _compress
    _uncompress
    make: *** [client1] Error 1
  • On Tue, 6 Mar 2001, Sam M. Daniel wrote:

    > _compress
    > _uncompress

    <snip>

    > I suspect that I have not included needed libraries.  What do you think?

    At a guess try -lz.

    Andrew
  • On Tue, 6 Mar 2001, Sam M. Daniel wrote:

    > I did try using -lz, but the system compained that it could find it.

    It exists under FreeBSD but I'm not running MacOS X atm.

    > I
    > went to /usr/lib and found liby.a and then tired using -ly.
    > Unfortunately, I got the same results.

    Yeah liby is the yacc library and not at all what you want. Using nm I
    checked and the compress and uncompress symbols are in libz under FreeBSD.
    If libz doesn't ship with MacOS X you may have to comile it yourself.

    Andrew
  • Instead of include -lz do -framwork Zip, this will change when Mac OS X
    final comes out, -lz will work then.

    >
    >
    >
    > On Tue, 6 Mar 2001, Sam M. Daniel wrote:
    >
    >> I did try using -lz, but the system compained that it could find it.
    >
    > It exists under FreeBSD but I'm not running MacOS X atm.
    >
    >> I
    >> went to /usr/lib and found liby.a and then tired using -ly.
    >> Unfortunately, I got the same results.
    >
    > Yeah liby is the yacc library and not at all what you want. Using nm I
    > checked and the compress and uncompress symbols are in libz under FreeBSD.
    > If libz doesn't ship with MacOS X you may have to comile it yourself.
    >
    > Andrew
    >
    > _______________________________________________
    > MacOSX-dev mailing list
    > <MacOSX-dev...>
    > http://www.omnigroup.com/mailman/listinfo/macosx-dev
    >
    >
  • At 6:38 PM -0700 3/6/01, Sam M. Daniel wrote:
    > I followed your advice and ran ranlib.  Here is what I got:
    >
    > [max:samp_db/capi/client1] sam% make
    > cc -o client1 client1.o -L/usr/local/lib/mysql  -lmysqlclient -dylib
    > /usr/bin/ld: Undefined symbols:
    > _compress
    > _uncompress
    > make: *** [client1] Error 1

    add a -framework Zip

    In X-GM, -lz will work instead.

    -pmb
previous month march 2001 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Go to today