| |

VerySource

 Forgot password?
 Register
Search
View: 2948|Reply: 12

How to set the mysql c api to use it?

[Copy link]

1

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-2-2 14:20:02
| Show all posts |Read mode
A simple program, copied online, but unable to compile,
I found all mysql * rpm in the installation disk, and all were installed.
When compiling a simple program, I get the following error. I don't know what else to install?
#Gcc test.c

test.c: In the function ‘main’:
test.c: 19: Warning: implicit declaration is not compatible with the built-in function 'exit'
/tmp/ccOfwWMG.o: In function `main ': test.c :(. text + 0x37): undefined reference to' mysql_init '
: test.c :(. text + 0x63): undefined reference to 'mysql_close'
collect2: ld returns 1



code show as below:

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

int main (int argc, char ** argv)
{

  MYSQL mysql; / * variation # 1 * /

  printf ("\n\n\tCopyright Aftab Jahan Subedar\n\t\thttp: //www.geocities.com/jahan.geo");
  printf ("\n\t\tjahan@geocities.com\n\t\tPhone: + 88027519050\n");

  if (mysql_init (&mysql) == NULL)
{
printf ("\nFailed to initate MySQL connection");
exit (1);
}

  / * now you can call any MySQL API function you like * /

  

   mysql_close (&mysql);

  }
Reply

Use magic Report

1

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-3-29 11:00:01
| Show all posts
I read the statement in "mysql / mysql.h", there are statements such as mysql_init (), mysql_close (), etc. Why does the compilation error?
It's weird!

It seems that no one understands this problem? I waited patiently for hours! depressed!
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-4-1 20:00:01
| Show all posts
You compile and try:
 gcc -lmysqlclient test.c
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 Invalid IP Address

Post time: 2020-4-2 08:30:01
| Show all posts
May be the reason there is no link library
Reply

Use magic Report

1

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-4-4 10:15:02
| Show all posts
gcc -lmysqlclient test.c
I have tried it for a long time, the error is as follows:
/ usr / bin / ld: cannot find -lmysqlclient
collect2: ld returns 1
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-4-4 17:00:02
| Show all posts
Add `mysql_config --.......` after gcc to see for yourself
Reply

Use magic Report

1

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-4-4 20:00:01
| Show all posts
Add `mysql_config --.......` after gcc to see for yourself

------------

Is a bright spot.
But what do you want me to add? I really don't understand! Soon after engaging in Linux, I humbly asked for advice!
Reply

Use magic Report

1

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-7-20 10:30:01
| Show all posts
I solved this problem myself, it took several days to get it done!

In fact, this problem is very small and not difficult, because it is still a common problem for beginners.
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-7-21 11:30:01
| Show all posts
There is no way, it can not be said that there are many masters in any sector;
What we don’t understand, we can only discuss together and make progress together. We always hope that the masters, what did the masters do in the first place?
Therefore, I think whether it is to solve the problem by myself or others helped to solve it, it is best to post the solution so that others can avoid detours.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-21 17:30:01
| Show all posts
Several static libraries of mySQL should be linked, and the -lib option should be added to gcc.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list