Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
03-28-2011, 09:30 PM
|
#1
|
Member
Registered: Dec 2008
Location: CH/IL
Distribution: Slackware 13.1 Fedora 12
Posts: 73
Rep:
|
C MySql
Hello everyone,
Im trying to write a program that interacts with MySql in C . Im using slackware 13.1 64 bit and Ive installed MySql , getting help from this page : http://www.basicconfig.com/linuxserv...ysql_slackware .
This is the program I have ( I know they arent any vars here , i just thought it wasnt necessary )
Code:
#include <stdio.h>
#include <mysql/my_global.h>
#include <mysql/my_sys.h>
#include <mysql/mysql.h>
int main(int argc, char** argv)
{
MY_INIT(argv[0]);
if(mysql_library_init(0, NULL, NULL)) {
fprintf(stderr, "mysql_library_init() failed\n");
exit(1);
}
conn = mysql_init(NULL);
if(conn == NULL) {
fprintf(stderr, "mysql_init() failed ( probably out of memory)\n");
exit(1);
}
if(mysql_real_connect(conn, opt_host_name, opt_user_name, opt_password,
opt_db_name, opt_port_num, opt_socket_name,
opt_flags) == NULL) {
fprintf(stderr, "mysql_real_connect() failed\n");
mysql_close(conn);
exit(1);
}
mysql_close(conn);
mysql_library_end();
exit(0);
}
This program is from the MySql website ( a tutorial they have up there ). When I run this program I get hundreds of lines of errors , nothing related to my program , but the headers, indicating that there are syntax errors and all kinds of other problems in them. So I was wondering if you could help me out with my problem .
Thanks in advance.
|
|
|
03-28-2011, 10:08 PM
|
#2
|
LQ Newbie
Registered: Feb 2008
Location: San Diego, CA
Distribution: Fedora 20, CentOS 6.5
Posts: 17
Rep:
|
Look at the mysqld log file and see if it gives you any clue.
|
|
|
03-28-2011, 10:20 PM
|
#3
|
Senior Member
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541
|
Quote:
Originally Posted by chymeira
When I run this program I get hundreds of lines of errors , nothing related to my program , but the headers, indicating that there are syntax errors and all kinds of other problems in them.
|
Syntax errors? These come when you compile the program; you may also get link errors when you attempt to build the executable. Yet above you claim you get these when you "run this program". Please elaborate a little further, because your statement makes no sense.
Please provide the GCC statement you use to compile (and link) the program. Also it would be helpful to provide the complete source listing, not just what you think is relevant.
|
|
|
03-28-2011, 10:24 PM
|
#4
|
Member
Registered: Dec 2008
Location: CH/IL
Distribution: Slackware 13.1 Fedora 12
Posts: 73
Original Poster
Rep:
|
I mean when I compile , srry about that ..
This is the gcc statement :
gcc -g -o connect connect.c -lmysqlclient -lz
This is how the tutorial told me to do it , like I said I just started an hour ago.
Here are some of the errors I get ( this is like 15% )
Quote:
/usr/include/mysql/my_global.h:80:23: error: my_config.h: No such file or directory
/usr/include/mysql/my_global.h:615:26: error: my_attribute.h: No such file or directory
/usr/include/mysql/my_global.h:651:21: error: my_dbug.h: No such file or directory
In file included from connect1.c:2:
/usr/include/mysql/my_global.h:690: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'size_socket'
/usr/include/mysql/my_global.h:815:2: error: #error "please add -DSTACK_DIRECTION=1 or -1 to your CPPFLAGS"
/usr/include/mysql/my_global.h:1000:2: error: #error Neither int or long is of 4 bytes width
/usr/include/mysql/my_global.h:1070: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'os_off_t'
/usr/include/mysql/my_global.h:1569: error: static declaration of 'rint' follows non-static declaration
/usr/include/mysql/my_global.h: In function 'rint':
/usr/include/mysql/my_global.h:1579: error: 'DBL_MANT_DIG' undeclared (first use in this function)
/usr/include/mysql/my_global.h:1579: error: (Each undeclared identifier is reported only once
/usr/include/mysql/my_global.h:1579: error: for each function it appears in.)
In file included from connect1.c:3:
/usr/include/mysql/my_sys.h:34:63: error: m_ctype.h: No such file or directory
/usr/include/mysql/my_sys.h:36:21: error: typelib.h: No such file or directory
In file included from connect1.c:3:
/usr/include/mysql/my_sys.h: At top level:
/usr/include/mysql/my_sys.h:227: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'my_thread_stack_size'
/usr/include/mysql/my_sys.h:235: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
/usr/include/mysql/my_sys.h:236: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
/usr/include/mysql/my_sys.h:237: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'compiled_charsets'
/usr/include/mysql/my_sys.h:240: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'my_file_opened'
|
The problem is I have all those files ( my_config.h .... etc )
Thank you
Last edited by chymeira; 03-28-2011 at 10:40 PM.
|
|
|
03-29-2011, 12:36 AM
|
#5
|
LQ Newbie
Registered: Feb 2008
Location: San Diego, CA
Distribution: Fedora 20, CentOS 6.5
Posts: 17
Rep:
|
Your compiler can not find the header files. Make sure you install the mysql source. In my case (I'm running Fedora) I had to install mysql-devel package.
Last edited by nigerag; 03-29-2011 at 12:38 AM.
|
|
|
03-29-2011, 12:39 AM
|
#6
|
LQ Newbie
Registered: Feb 2008
Location: San Diego, CA
Distribution: Fedora 20, CentOS 6.5
Posts: 17
Rep:
|
My apologies. I've just noticed you mentioned you had these files.
|
|
|
03-29-2011, 03:59 AM
|
#7
|
Senior Member
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541
|
Chymeira,
I'm almost certain that there is something wrong with the installation of your MySQL development package. I have this package (perhaps a meta-package) installed on my Ubuntu 10.04 system, and I had no trouble compiling/linking the following program (note, it is not important that it wont run successfully; the point it to compile it):
Code:
#include <mysql/mysql.h>
#include <stddef.h> /* for NULL */
int main(void)
{
MYSQL* conn = NULL;
char hostname[20];
char username[20];
char password[20];
char database[20];
char socketname[20];
unsigned int port = 9000;
unsigned long flag = 0;
mysql_library_init(0, NULL, NULL);
conn = mysql_init(NULL);
mysql_real_connect(conn, hostname, username, password, database, port, socketname, flag);
mysql_close(conn);
mysql_library_end();
return 0;
}
To build:
Code:
gcc -Wall mysql.c -lmysqlclient
I would recommend that you re-verify the installation of the MySQL development package. Did you use your system's package manager to install it, or did you install it manually from a tar-ball containing the source code?
EDIT:
Doh! It turns out the errors are from including the following header files:
Code:
#include <mysql/my_global.h>
#include <mysql/my_sys.h>
I guess the moral of the story is to not include them, if they are unnecessary. The other alternative, and probably the best solution, is to always compile with the path to the MySQL header files specified:
Code:
gcc -Wall -I/usr/include/mysql mysql.c -lmysqlclient
Last edited by dwhitney67; 03-29-2011 at 04:04 AM.
|
|
|
03-29-2011, 10:40 AM
|
#8
|
Member
Registered: Dec 2008
Location: CH/IL
Distribution: Slackware 13.1 Fedora 12
Posts: 73
Original Poster
Rep:
|
Thank you very much for all your replies .
What I did is compile like the following ( ty for that dwhitney ) :
gcc -Wall -I /usr/include/mysql connect1.c -o connect1 -lmysqlclient
and it works fine now.
|
|
|
03-29-2011, 11:09 AM
|
#9
|
Senior Member
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541
|
It should be noted that by using the -I option, you no longer are required to specify the header files using their respective directory; for example, the following should be sufficient when using -I/usr/include/mysql:
Code:
#include <mysql.h>
...
|
|
|
All times are GMT -5. The time now is 08:47 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|