How to solve the error reported by using the MySQL header file in C ++ code

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: The MySQL4.x and MySQL5.x header files are incompatible. It is best to use the 5.x version.
Supplement: Some versions can only reference # include <mysql. h>. If they are other versions, an error occurs in a file in the C standard library.

Related Article

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.