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.