欢迎来到天天文库
浏览记录
ID:8812374
大小:18.61 KB
页数:3页
时间:2018-04-08
《cc连接mysql(gcc版)以及vc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、1、从mysql-noinstall-5.1.30-win32.zip包中解压include,lib两个目录到 使用C:vcprojectsmysql-5.1.30中 2、参考本博客《WindowsXP下MinGW的安装与配置》建好Windows下GCC的开发环境。 3、进入目录C:vcprojectsmysql-5.1.30libopt执行命令: reimp-dlibmysql.lib dlltool-k-dlibmysql.def-llibmysql.a 生成gcc所需链接的mysql库libmysql 4、在C:vcprojects
2、learn目录下创建文件visitsql.c(网友代码修改版) #include#include#include#includeusingnamespacestd;intmain(){//connectionparams//FILE*file;char*host="localhost";char*user="root";char*pass="12345";char*db="mysql";//sockMYSQL*sock;MYSQL_RES*results;MYSQL_ROW
3、record;sock=mysql_init(0);if(sock)cout<<"sockhandleok!"<4、character_set(sock,"gb2312");//connectioncharactersetcout<<"connectioncharacterset:"<5、户名");while(record=mysql_fetch_row(results)){printf("%st%s",record[0],record[1]);}mysql_free_result(results);//system("PAUSE");//closingconnectionmysql_close(sock);returnEXIT_SUCCESS;}5、创建一个批处理文件build.bat: setMYSQL_CLIB=C:vcprojectsmysql-5.1.30 setC_INCLUDE_PATH=%C_INCLUDE6、_PATH%;%MYSQL_CLIB%include setCPLUS_INCLUDE_PATH=%CPLUS_INCLUDE_PATH%;%MYSQL_CLIB%include setLIBRARY_PATH=%LIBRARY_PATH%;%MYSQL_CLIB%libopt g++-ovisitsqlvisitsql.c-llibmysql 执行该批处理,生成visitsql.exe执行该程序结果: sockhandleok! connectionok! connectioncharacterset:gb2312 主机 用户名 loca7、lhost root 6、比较visitsql大小: gcc版 488KB vc++debug版 40KB vc++release版10KB 7、另从网上摘抄 如果你的dlltool产生的libmysql.a是空文件的话,如下操作: cd{mysql}/lib/opt reimplibmysql.lib dlltool.exe-d{mysql++}/libmysqlclient.def-emysqlclient.exp-lmysqlclient.a-Sas 备注: mingw-utils-0.3.tar.gz binutil8、s-2.17.50-20060824-1.tar.gz //reimpmysqlclient.
4、character_set(sock,"gb2312");//connectioncharactersetcout<<"connectioncharacterset:"<5、户名");while(record=mysql_fetch_row(results)){printf("%st%s",record[0],record[1]);}mysql_free_result(results);//system("PAUSE");//closingconnectionmysql_close(sock);returnEXIT_SUCCESS;}5、创建一个批处理文件build.bat: setMYSQL_CLIB=C:vcprojectsmysql-5.1.30 setC_INCLUDE_PATH=%C_INCLUDE6、_PATH%;%MYSQL_CLIB%include setCPLUS_INCLUDE_PATH=%CPLUS_INCLUDE_PATH%;%MYSQL_CLIB%include setLIBRARY_PATH=%LIBRARY_PATH%;%MYSQL_CLIB%libopt g++-ovisitsqlvisitsql.c-llibmysql 执行该批处理,生成visitsql.exe执行该程序结果: sockhandleok! connectionok! connectioncharacterset:gb2312 主机 用户名 loca7、lhost root 6、比较visitsql大小: gcc版 488KB vc++debug版 40KB vc++release版10KB 7、另从网上摘抄 如果你的dlltool产生的libmysql.a是空文件的话,如下操作: cd{mysql}/lib/opt reimplibmysql.lib dlltool.exe-d{mysql++}/libmysqlclient.def-emysqlclient.exp-lmysqlclient.a-Sas 备注: mingw-utils-0.3.tar.gz binutil8、s-2.17.50-20060824-1.tar.gz //reimpmysqlclient.
5、户名");while(record=mysql_fetch_row(results)){printf("%st%s",record[0],record[1]);}mysql_free_result(results);//system("PAUSE");//closingconnectionmysql_close(sock);returnEXIT_SUCCESS;}5、创建一个批处理文件build.bat: setMYSQL_CLIB=C:vcprojectsmysql-5.1.30 setC_INCLUDE_PATH=%C_INCLUDE
6、_PATH%;%MYSQL_CLIB%include setCPLUS_INCLUDE_PATH=%CPLUS_INCLUDE_PATH%;%MYSQL_CLIB%include setLIBRARY_PATH=%LIBRARY_PATH%;%MYSQL_CLIB%libopt g++-ovisitsqlvisitsql.c-llibmysql 执行该批处理,生成visitsql.exe执行该程序结果: sockhandleok! connectionok! connectioncharacterset:gb2312 主机 用户名 loca
7、lhost root 6、比较visitsql大小: gcc版 488KB vc++debug版 40KB vc++release版10KB 7、另从网上摘抄 如果你的dlltool产生的libmysql.a是空文件的话,如下操作: cd{mysql}/lib/opt reimplibmysql.lib dlltool.exe-d{mysql++}/libmysqlclient.def-emysqlclient.exp-lmysqlclient.a-Sas 备注: mingw-utils-0.3.tar.gz binutil
8、s-2.17.50-20060824-1.tar.gz //reimpmysqlclient.
此文档下载收益归作者所有