前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C++与MySQL的冲突

C++与MySQL的冲突

作者头像
一见
发布2018-08-07 15:41:26
9920
发布2018-08-07 15:41:26
举报
文章被收录于专栏:蓝天

当在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 #include #include 在头文件中只进行引用声明: 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 ,包含其它会报C++标准库中某文件错误。

原帖发在我的论坛:

http://bbs.hadoopor.com/thread-1564-1-1.html

http://bbs.hadoopor.com/thread-1564-1-1.html

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2010/09/01 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 MySQL
腾讯云数据库 MySQL(TencentDB for MySQL)为用户提供安全可靠,性能卓越、易于维护的企业级云数据库服务。其具备6大企业级特性,包括企业级定制内核、企业级高可用、企业级高可靠、企业级安全、企业级扩展以及企业级智能运维。通过使用腾讯云数据库 MySQL,可实现分钟级别的数据库部署、弹性扩展以及全自动化的运维管理,不仅经济实惠,而且稳定可靠,易于运维。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档