Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / Call MYSQL library function failed

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Call MYSQL library function failed
#3073
Posted by: mooncake 2003-12-13 20:10:09
Hi, when i included mysql library, and try to call the function, but it prompt me this error message:

 
[Linker error] undefined reference to `mysql_init@4'

What can i do now?  Thank you.

#include <iostream>
#include <stdlib.h>
#include <mysql/mysql.h>

using namespace std;

int main(int argc, char *argv[])
{
  MYSQL *mysql;
  
  mysql_init(mysql);
  system("PAUSE");	
  return 0;
}
Meow~
Message2. Re: Call MYSQL library function failed
#3074
Posted by: lea 2003-12-13 22:51:43
Have you added the sql-lib to your linker?
Message3. Re: Call MYSQL library function failed
#3077
Posted by: mooncake 2003-12-14 09:22:21
How to add about it?

Thank you..

Meow~
Message4. Re: Call MYSQL library function failed
#3078
Posted by: lea 2003-12-14 15:21:22
You included only the header, so you have to link the definitions with your programm.
How to do that is compiler dependent.
With Dev-Cpp you can add a lib in the linker box with -mylib.
The path must be set, of course.
Message5. Re: Call MYSQL library function failed
#3079
Posted by: mooncake 2003-12-14 16:40:24
Hi, i had included mysql library into library

and i use mysql++-1.7.9

where to get mylib?  the lib is that the directory called lib?

Thank you.

Meow~
Message6. Re: Call MYSQL library function failed
#3080
Posted by: mooncake 2003-12-14 19:21:14
when i include libmysql.lib into linker...
start compile, but, display me this error message:

 file not recognized C:HomeCompilerDev-Cppliblibmysql.LIB
File format not recognized


Why?

Thank you...

Meow~
Message7. Re: Call MYSQL library function failed
#3081
Posted by: upCASE 2003-12-14 21:28:24
Hi!
Because *.lib are MS VC libraries and are binary incompatible with gcc *.a libs. Using Dev-C++ I suggest checking WebUpdate. There should be a mySQL devpack out there.
I nothing else works: Drop me a line and when I find some time I'll mail you a proper lib.
BTW: The lib is more or less the "loader" for the DLL, so you could get a lib yourself using reimp.

upcase
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message8. Re: Call MYSQL library function failed
#3082
Posted by: mooncake 2003-12-14 21:34:54
Thank you Upcase.

Actually i ever to use mysql dll, but, i don't know the prototype... So...

Meow~
Message9. Re: Call MYSQL library function failed
#3090
Posted by: upCASE 2003-12-15 21:13:23
Hi!
You'll only have to link libmysql.a with your code. This lib will then load mysql.dll dynamically at runtime. You'll have to make sure that mysql.dll can be found either in the program dir or in the system dir.
Do you have a working libmysql.a for your version of gcc.

upcase
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message10. Re: Call MYSQL library function failed
#3095
Posted by: mooncake 2003-12-16 17:03:20
I dont have  libmysql.a
:(

Do you have it?

Thank you...
Meow~
Message11. Re: Call MYSQL library function failed
#3097
Posted by: upCASE 2003-12-16 21:28:34
Hi!
You got mail! :)
It contains your christmas present :))

upcase
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message12. Re: Call MYSQL library function failed
#3098
Posted by: mooncake 2003-12-16 22:00:00
Hi Upcase, thank you.. :)

What happen to me when i call mysql_connect, it display me this error message?

11 C:Documents and SettingsGordon Lim Hon WeiMy Documentsmain.cpp
`mysql_connect' undeclared (first use this function)

if i replace to mysql_real_connect, it display me another error message ->299 C:HomeCompilerDev-Cppincludemysqlmysql.h
too few arguments to

MYSQL *       STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
                  const char *user,
                  const char *passwd,
                  const char *db,
                  unsigned int port,
                  const char *unix_socket,
                  unsigned int clientflag); -->debugger focus there

#include <iostream>
#include <stdlib.h>
#include <mysql/mysql.h>

using namespace std;

int main(int argc, char *argv[])
{
  MYSQL *mysql;
  mysql_init(mysql);
  mysql_connect(mysql,"localhost","root","");
  
  system("PAUSE");	
  return 0;
}

thank you.. :)
Meow~
Message13. Re: Call MYSQL library function failed
#3100
Posted by: upCASE 2003-12-17 23:58:28
Hi!
Quoting from the API reference, mysql_connect() is considered to be deprecated. It's #ifndef'ed so that if your not using a special #define it will give you this warning, because the prototyp isn't found.

There are two solutions:
1. The "not" official one: Use -DUSE_OLD_FUNCTIONS in your project settings and use mysql_connect(). It should work then.
2. The official one: Use mysql_real_connect()
Try with

#include <iostream>
#include <stdlib.h>
#include <mysql/mysql.h>

using namespace std;

int main(int argc, char *argv[])
{
  MYSQL *mysql;
  mysql_init(mysql);
  mysql_real_connect(mysql,"localhost","root","",dbname, 0, NULL, 0);

  system("PAUSE");   
  return 0;
}

where dbname should be replaced by the name of the DB you want to connect to.

upcase
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message14. Re: Call MYSQL library function failed
#3103
Posted by: mooncake 2003-12-18 21:39:13
thank you, it gonna ok now.. :)

Meow~
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Wed 2024-12-11  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0