The process of generating libmysql. A for DEV-C ++ and the configuration of accessing MySQL database environment in the C language of devc ++ in Windows
Source: Internet
Author: User
This article consists of two parts: 1. Process 2 of generating libmysql. A for DEV-C ++. Devc ++ in Windows C Language Access MySQL database environment configuration 1. The process of generating libmysql. A for DEV-C ++ aims: Because DEV-C ++ uses GCC, MySQL's libmysql. dll only supports visual stdio. Therefore, libmysql. A needs to be generated from libmysql. dll. The command used is dlltool -- input-Def libmysql. def -- dllname libmysql. DLL -- output-lib libmysql. a-K in order to make the previous command correctly executed, note the following points: (1) dlltoll.exe exists in the DEV-C ++ directory (c: \ Program Files \ DEV-CPP \ mingw32 \ bin ); while libmysql. def and libmysql. dll exists in the MySQL directory. First, you need to copy libmysql. Def and libmysql. DLL to the directory where dlltoll.exe is located. Copy dlltoll.exe to the directory of libmysql. dll in the MySQL directory. This is because libmysql. in the full path of the DLL, there is "MySQL Server 5.1" with spaces in the middle, which affects the execution of the dlltool command. The error message is generated considering that dlltoll.exe exists in C: \ Program Files \ DEV-CPP \ mingw32 \ bin, you can put libmysql. DLL copy to this directory "... Installation problem cannot exec 'as' "(2) the libmysql. Def file in the previous command is not the one that exists after MySQL is installed. Instead, you must use the following command, which is generated based on libmysql. Lib. Reimp-D libmysql. lib (it seems that reimp is not included in the installation package of the DEV-C and needs to be downloaded separately) can be compared to the new libmysql. def and MySQL files of the same name in another directory are different in size. If you use the libmysql. Def file that comes with MySQL by mistake, a series of errors similar to the following will appear when you execute the dlltool command. Undefined reference to 'mysql _ real_query @ 12' reimp is included in mingw-utils. Therefore, you need to download mingw-utils. NOTE: If libmysql is not specified in project --- project option --- parameters linker in the DEV-C. an error similar to undefined reference to 'mysql _ init @ 4' may also occur in the full path of. (3) generate libmysql. after a, you also need to add libmysql In the linker column in The DEV-C + + 'Project option' | compiler options | linker sheet. the full path (including the file name) of ). II. For access to the MySQL database environment in devc ++ C language in windows, refer to the following two articles: Article (1) http://hi.baidu.com/leeyou1450/blog/item/78fdd438ec9986f63a87ceaa.html (2) DEV-C 4.9.2, WindowsXP system, according to the instructions of the two articles but fails to set, it has been improved. The details are as follows. A) Program To use the MySQL database, you must add libmysql to the linker column in project | 'Project option' | compiler options | linker sheet. a's full path B) to use multithreading in a program, you need to add c to the linker column in project | project option '| compiler options | linker sheet: \ Program Files \ DEV-CPP \ Lib \ libws2_32.a (the file libwsock32.a in the same directory is an old version, so the application libws2_32.a) C) we recommend that you add-wall and-wd in the project | 'Project option' | compiler options |'s copliler and C ++ compiler boxes. CT option '| directories | add c: \ Program Files \ mysql \ mysql-5.1.38-win32 \ include under include directories so that # include "mysql. H" can be included in the XXX. cpp file ". The strange thing is that c: \ Program Files \ mysql \ mysql-5.1.38-win32 \ include does not work in tools --- compiler options --- directories --- C uplodes or C ++ uplodes) tools --- compiler options --- directories --- Libraries add c: \ Program Files \ mysql \ mysql-5.1.38-win32 \ Lib \ OPT Code Test whether the environment settings of the DEV-C are correct # include <cstdlib> # include <iostream> using namespace STD; # include <windows. h> # include "MySQL. H "# include <stdio. h> # include <stdlib. h> # include <Winsock. h>/* int main () {wsadata; wsastartup (0x101, (lpwsadata) & wsadata); System ("pause"); Return 0 ;} */INT main () {MySQL; // MySQL connects to mysql_res * res; // This structure indicates a query result set mysql_row row of the returned row; // The char * query statement for the type-safe of the row data; // the query statement Int T, R; mysql_init (& MySQL); If (! Mysql_real_connect (& MySQL, "localhost", "root", "", "MySQL", 3306, null, 0 )) {printf ("error connecting to database % s \ n", mysql_error (& MySQL);} else printf ("connected... \ n "); query =" set Character Set GBK "; // sets the encoding t = mysql_real_query (& MySQL, query, (unsigned INT) strlen (query )); if (t) {printf ("encoding setting failed \ n");} query = "select * from user"; t = mysql_real_query (& MySQL, query, (unsigned INT) strlen (query); If (t) {printf ("exceptions occurred during query execution: % s", mysql_error (& MySQL ));} else printf ("[% s] built successfully \ n", query); Res = mysql_store_result (& MySQL); While (ROW = mysql_fetch_row (RES )) {for (t = 0; t <mysql_num_fields (RES); t ++) {printf ("% s:", row [T]);} printf ("\ n");} mysql_free_result (RES); // sleep (1); scanf ("% d", & T); Return 0 ;}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.