ProgrammingThis 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.
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.
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 .
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.
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 )
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.
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:
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:
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:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.