MYSQL headers conflict with STL <algorithm> in C ++

// File test.cpp
#include <my_global.h>
#include <algorithm>
int main()
{
    return 0;
}

Compiled with: g ++ -c -I / usr / local / mysql / include / mysql / test.cpp, where / usr / local / mysql is the mysql installation directory. The compiler then reports the following errors:

In the file included in / usr / include / c ++ / 4.4 / algorithm: 61, from test.cpp: 3: / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 232: 56: error: the "min" macro passed 3 arguments, but takes only 2 / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 253: 56: error: the "max" macro passed 3 arguments, but takes only 2 in the file, included in / usr / include / c ++ / 4.4 / bits / stl_algo.h: 61, from / usr / include / c ++ / 4.4 / algorithm: 62, from test.cpp: 3: / usr / include / c ++ / 4.4 / bits / algorithmfwd.h: 353: 41: error: the macro "max" passed 3 arguments, but takes only 2 / usr / include / c ++ / 4.4 / bits / algorithmfwd.h: 364: 41: error: the macro "min" passed 3 arguments, but takes only 2 In the file included in / usr / include / c ++ / 4.4 / algorithm: 61, from test.cpp: 3: / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 186: error: expected unqualified-id to 'const / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 186: error: expected') to 'const / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 186: error: expected ') to' const / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 186: error: expected initializer to 'const / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 209: error: expected unqualified identifier before 'const / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 209: error: expected') before 'const / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 209: error: expected') to 'const / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 209: error : expected initializer to 'const / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 232: error:' std :: min declared as' built-in variable / usr / include / c ++ / 4.4 / bits / stl_algobase.h:232: error: declaration of the template 'const _Tp & stand :: min / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 235: error: expected primary expression before' if / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 235: error: expected '} before' if / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 237: error: expected unqualified identifier before returning / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 253: error: max declared as a built-in variable / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 253: error: template declaration 'const _Tp & Maximum / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 256: error: expected primary expression before 'if / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 256: error: expected'} before 'if / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 258: error :expected unqualified identifier before returning / usr / include / c ++ / 4.4 / bits / stl_algobase.h: 259: error: expected declaration before '} token

, my_global.h - , my_global.h :

// File test.cpp
namespace MYSQL_NAMESPACE {
    #include <my_global.h>
}
#include <algorithm>
int main()
{
    return 0;
}

, . :

// File test.cpp
#include <algorithm>
#include <my_global.h>
int main()
{
    return 0;
}

.

- , ?

TKS!

+3
3

, mysql min.

#if !defined(max)
#define max(a, b)       ((a) > (b) ? (a) : (b))
#define min(a, b)       ((a) < (b) ? (a) : (b))
#endif

MySQL 28184. , . ​​ 5.1.23, 6.0.4 .

+7

-, , min/max , .

:

#include <my_global.h>
#undef min
#undef max
#include <algorithm>

, :)

+3

, my_global.h , algorithm , . , , , , my_global.h clobbers, , , , . , , .

Hence it sounds like a broken one my_global.h, but if everything works, just use the attached order that works and goes with it. In any case, my preferred option includes ordering — standard library headers followed by external library headers and then internal headers.

0
source

Source: https://habr.com/ru/post/1783469/


All Articles