Conflicts between C ++ and MySQL

Source: Internet
Author: User

When the MySQL header file is directly referenced in the C ++ code, the following error may occur:

In file encoded ded 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

Solution:
Try to wrap MySQL twice so that the caller cannot see the MySQL header file, for example, including in CPP:
# Include <my_global.h>
# Include <my_sys.h>
# Include <mysql. h>


Only the following statements can be referenced in the header file:
Struct st_mysql;
Struct st_mysql_res;

Typedef long num_t;
Typedef char ** mysql_row;/** return data as array of strings */


Do not include the header file directly to the MySQL header file, and ensure that only the MySQL file is included in one CPP file. Otherwise, you may encounter many inexplicable compilation errors. If you do not think of this, the error cause may not be found even if it takes one day.



Supplement:
Mysql4.x and mysql5.x header files are not compatible, preferably version 5.x

Supplement:
Some versions can only reference # include <mysql. h>. Otherwise, a file error in the C ++ standard library is reported.

The original post is posted on my Forum:

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

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.