博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++与MySQL的冲突
阅读量:7123 次
发布时间:2019-06-28

本文共 1965 字,大约阅读时间需要 6 分钟。

当在C++代码中,直接引用MySQL文件时,可能会遇到如下错误

In file included from /usr/include/c++/4.1.0/bits/char_traits.h:46,
                 from /usr/include/c++/4.1.0/string:46,
/usr/include/c++/4.1.0/bits/stl_algobase.h:92:28: error: macro "swap" requires 3 arguments, but only 2 given
/usr/include/c++/4.1.0/bits/stl_algobase.h:127:26: error: macro "swap" requires 3 arguments, but only 2 given

/usr/include/c++/4.1.0/bits/vector.tcc:176:20: error: macro "swap" requires 3 arguments, but only 1 given
/usr/include/c++/4.1.0/cctype:70: error: '::isalnum' has not been declared
/usr/include/c++/4.1.0/cctype:71: error: '::isalpha' has not been declared
/usr/include/c++/4.1.0/cctype:72: error: '::iscntrl' has not been declared
/usr/include/c++/4.1.0/cctype:73: error: '::isdigit' has not been declared
/usr/include/c++/4.1.0/cctype:74: error: '::isgraph' has not been declared
/usr/include/c++/4.1.0/cctype:75: error: '::islower' has not been declared
/usr/include/c++/4.1.0/cctype:76: error: '::isprint' has not been declared
/usr/include/c++/4.1.0/cctype:77: error: '::ispunct' has not been declared
/usr/include/c++/4.1.0/cctype:78: error: '::isspace' has not been declared
/usr/include/c++/4.1.0/cctype:79: error: '::isupper' has not been declared
/usr/include/c++/4.1.0/cctype:80: error: '::isxdigit' has not been declared
/usr/include/c++/4.1.0/cctype:81: error: '::tolower' has not been declared
/usr/include/c++/4.1.0/cctype:82: error: '::toupper' has not been declared

解决办法:
尽量对MySQL进行二次包装,让调用者看不到MySQL头文件,如在CPP中包含:
#include <my_global.h>
#include <my_sys.h>
#include <mysql.h>


在头文件中只进行引用声明:
struct st_mysql;
struct st_mysql_res;

typedef long num_t;
typedef char ** MYSQL_ROW;  /** return data as array of strings */

不要在头文件直接include到MySQL的头文件,而且保证只在一个CPP文件中有对MySQL文件的include,否则你可能遇到很多莫名其妙的编译错误,如果不想到这一点,即使花一天时间也未必能找到错误原因。


补充:
MySQL4.x和MySQL5.x头文件不兼容的,最好使用5.x版本

补充:
有些版本只能引用#include <mysql.h>,包含其它会报C++标准库中某文件错误。

原帖发在我的论坛:
    本文转自eyjian 51CTO博客,原文链接:http://blog.51cto.com/mooon/909758,如需转载请自行联系原作者
你可能感兴趣的文章
Form 重置记录编号(app_record.for_all_record)
查看>>
VC之美化界面(内容覆盖十分全面,经典)
查看>>
国外经典设计:12个漂亮的移动APP网站案例
查看>>
pl/sql programming 15 数据提取
查看>>
DBCP(一)数据源配置文件
查看>>
C++ map 映照容器
查看>>
重新想象 Windows 8 Store Apps (40) - 剪切板: 复制/粘贴文本, html, 图片, 文件
查看>>
[WinAPI] API 13 [遍历指定目录 打印文件和其他属性]
查看>>
字对齐、半字对齐、字节对齐的理解
查看>>
杀毒软件导致YourSQLDba备份失败
查看>>
struts2漏洞原理及解决办法
查看>>
利用cca进行fmri分析
查看>>
Oracle Dataguard之switchover
查看>>
Step-by-Step XML Free Spring MVC 3 Configuration--reference
查看>>
关于LD_DEBUG (转载)
查看>>
linux2.6.30.4内核移植(4)——完善串口驱动
查看>>
Timer&TimerTask原理分析
查看>>
GDI+ 和GDI
查看>>
日常工作中的点滴总结from 2014-03
查看>>
Yii的学习(2)--数据访问对象 (DAO)
查看>>