MySQL Lists are EOL. Please join:

List:General Discussion« Previous MessageNext Message »
From:Thimble Smith Date:March 19 1999 9:11pm
Subject:Re: [MySQL] link error
View as plain text  
Hi.  First, you really should use the 'mysqlbug' program to report
problems - it tells us a lot of useful information about your
setup (information which you did not include).  Look in the manual
for information on how to file a useful problem report.

Second, any time you're having trouble compiling anything, it's
really important to give the exact command used to compile (and
give version information for the tools you're using).  Thank you
for at least including the real text of [part of] the error message.

Third, to answer your question:  probably you need to tell your
linker to link against the mysqlclient library.  Usually you
do it like this:

    cc -Wall -O2\
       -lmysqlclient -lm\
       -o my_program

If you're not familiar with those flags, look at your compiler

Fourth, you're missing some crucial calls in your C program.  You
need to call mysql_init() before you call any other mysql functions.
You should call mysql_disconnect() after you're through.

Fifth, it's better to put the path to the include file in your compile
line (like I did in the example above, using the -I flag) instead of
in your source code.  If you move your installation, you shouldn't have
to edit all of your source code.  Blech.

Maybe you are just making a test program, and you're going to do it all
"correctly" once you get the test working.  My experience says that it
is most important in "test" programs to do everything "correctly" - if
you don't, then you're testing won't match your real environment!

If my answers are way off track, please send a complete problem report
so that we'll have a better idea of what you need!



On Fri, Mar 19, 1999 at 03:54:07PM -0500, RaymanJ@stripped wrote:
> Hello,
> 	I am testing out how to connect to MySQL with a C program.  This is the first
> time for me to do this. 
> 	Problem:
> 		When ever I compile my program it gives me an error message as below.
> /var/tmp/ccyP17051.o: Undefined symbol `_mysql_connect' referenced from text
> seg
> ment
> 	I have tried to locate this file but to no avail.  Can anyone help me with
> this.  Why is it happening and how to fix it.
> My code below:
> #include<stdio.h>
> #include<stdlib.h>
> #include"/usr/ports/databases/mysql321/work/mysql-3.21.33b/include/mysql.h"
> MYSQL mysql;
> void exiterr(int exitcode)
> {
>         fprintf( stderr, "%s\n", mysql_error(&mysql) );
>         exit( exitcode );
> }
> int main()
> {
>         mysql_connect(&mysql, NULL, NULL, NULL);
>                 exiterr(1);
>         if (mysql_select_db(&mysql,"test"))
>                 exiterr(2);
> }
> Thanks,
> Ray
> ---------------------------------------------------------------------
> To request this thread, e-mail mysql-thread643@stripped
> To unsubscribe, send a message to the address shown in the
> List-Unsubscribe header of this message. If you cannot see it,
> e-mail mysql-unsubscribe@stripped instead.
> For archive commands, etc, e-mail: mysql-help@stripped
[MySQL] link errorRaymanJ19 Mar
  • Re: [MySQL] link errorPaul DuBois19 Mar
  • Re: [MySQL] link errorThimble Smith19 Mar
  • Re: [MySQL] link errorWade Maxfield19 Mar