|
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next 1 |
1. Call MYSQL library function failed #3073 |
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~ |
2. 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? |
3. Re: Call MYSQL library function failed #3077 |
How to add about it?
Thank you..
Meow~ |
4. 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. |
5. Re: Call MYSQL library function failed #3079 |
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~ |
6. Re: Call MYSQL library function failed #3080 |
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~ |
7. 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.
upcaseupCASE ----------------------------------- If it was hard to write, it should be hard to read!- Do. Or do not. There is no try! |
8. Re: Call MYSQL library function failed #3082 |
Thank you Upcase.
Actually i ever to use mysql dll, but, i don't know the prototype... So...
Meow~ |
9. 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.
upcaseupCASE ----------------------------------- If it was hard to write, it should be hard to read!- Do. Or do not. There is no try! |
10. Re: Call MYSQL library function failed #3095 |
I dont have libmysql.a :(
Do you have it?
Thank you...Meow~ |
11. 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 :))
upcaseupCASE ----------------------------------- If it was hard to write, it should be hard to read!- Do. Or do not. There is no try! |
12. Re: Call MYSQL library function failed #3098 |
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~ |
13. 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.
upcaseupCASE ----------------------------------- If it was hard to write, it should be hard to read!- Do. Or do not. There is no try! |
14. Re: Call MYSQL library function failed #3103 |
thank you, it gonna ok now.. :)
Meow~ |
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next 1 |