// 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 install directory.Then the compiler report the following errors:
In file included from /usr/include/c++/4.4/algorithm:61, from test.cpp:3: /usr/include/c++/4.4/bits/stl_algobase.h:232:56: error: macro "min" passed 3 arguments, but takes just 2 /usr/include/c++/4.4/bits/stl_algobase.h:253:56: error: macro "max" passed 3 arguments, but takes just 2 In file included from /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: macro "max" passed 3 arguments, but takes just 2 /usr/include/c++/4.4/bits/algorithmfwd.h:364:41: error: macro "min" passed 3 arguments, but takes just 2 In file included from /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 before ‘const’ /usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected ‘)’ before ‘const’ /usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected ‘)’ before ‘const’ /usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected initializer before ‘const’ /usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected unqualified-id 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 ‘)’ before ‘const’ /usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected initializer before ‘const’ /usr/include/c++/4.4/bits/stl_algobase.h:232: error: ‘std::min’ declared as an ‘inline’ variable /usr/include/c++/4.4/bits/stl_algobase.h:232: error: template declaration of ‘const _Tp& std::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-id before ‘return’ /usr/include/c++/4.4/bits/stl_algobase.h:253: error: ‘max’ declared as an ‘inline’ variable /usr/include/c++/4.4/bits/stl_algobase.h:253: error: template declaration of ‘const _Tp& max’ /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-id before ‘return’ /usr/include/c++/4.4/bits/stl_algobase.h:259: error: expected declaration before ‘}’ token
I think that there's some name conflict between my_global.h and algorithm, so I wrap my_global.h in a namespace:
// File test.cpp
namespace MYSQL_NAMESPACE {
#include <my_global.h>
}
#include <algorithm>
int main()
{
return 0;
}
But it doesn't help, the compiler still report the same errors. Then I change the include order as following:
// File test.cpp
#include <algorithm>
#include <my_global.h>
int main()
{
return 0;
}
Every thing goes well now.
Does Anybody Really Know What The Problem It Is?
TKS!
windows.h
has this same problem -- you turn off definition ofmin
andmax
using the macroNOMINMAX
there) – Billy ONeal