Poehli
Poehli

Reputation: 307

MariaDB C++ Connector compile

I'm trying to compile a simple c++ file that is suppose to use the mariadbc++ connector. For some reason I ran into alot of trouble with that. I get strange error messages. I neither understand them, nor do I know how to fix them.
I did a lot of research, but either nobody else ran into these problems or I just cant find them.

I installed following packages:

mariadb-client
mariadb-client-5.5
mariadb-server
libmariadbclient18
libmysqlclient18
libmysqlcppconn7
libmysqlcppconn-dev
libmariadbclient-dev
libmariadb-dev

I'm on a x64 Ubuntu 14.04 System (well Pinguy OS, but I guess, that doesn't matter)

I tried to build following programm:

#include <my_global.h>
#include <mysql.h>
#include "mysql_driver.h" 

int main(int argc, char **argv)
{  
  sql::mysql::MySQL_Driver *driver;
  sql::Connection *con;
  sql::Statement *stmt;
  driver = sql::mysql::MySQL_Driver::get_mysql_driver_instance();
  con = driver->connect("tcp://localhost:3306","root", "herein");
  if (!con->isValid()) exit(1);

  stmt = con->createStatement();
  stmt->execute("use testtb");

  stmt->execute("INSERT INTO Testtable(id, label) VALUES (1, 1)");
  delete stmt;
  delete con;
  return 1;
}

And I tried this command:

g++ -lmysqlcppconn -g src/test_mariadb.cpp -o bin/test_mariadb $(mysql_config --cflags) $(mysql_config --libs)

where under in src/ my source files are and in bin/ my binaries.

And finally the Compile Errors I get:

In file included from /usr/include/c++/4.8/bits/char_traits.h:39:0,
                 from /usr/include/c++/4.8/ios:40,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from /usr/include/boost/assert.hpp:82,
                 from /usr/include/boost/smart_ptr/scoped_ptr.hpp:15,
                 from /usr/include/boost/scoped_ptr.hpp:14,
                 from /usr/include/mysql_driver.h:30,
                 from src/test_mariadb.cpp:3:
/usr/include/c++/4.8/bits/stl_algobase.h:239:56: error: macro "min" passed 3 arguments, but takes just 2
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
                                                        ^
/usr/include/c++/4.8/bits/stl_algobase.h:260:56: error: macro "max" passed 3 arguments, but takes just 2
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
                                                        ^
In file included from /usr/include/boost/mpl/aux_/begin_end_impl.hpp:21:0,
                 from /usr/include/boost/mpl/begin_end.hpp:18,
                 from /usr/include/boost/mpl/iter_fold.hpp:18,
                 from /usr/include/boost/variant/detail/initializer.hpp:28,
                 from /usr/include/boost/variant/variant.hpp:31,
                 from /usr/include/boost/variant.hpp:17,
                 from /usr/include/cppconn/connection.h:31,
                 from /usr/include/cppconn/driver.h:30,
                 from /usr/include/mysql_driver.h:32,
                 from src/test_mariadb.cpp:3:
/usr/include/boost/mpl/aux_/has_begin.hpp:20:57: error: macro "test" passed 2 arguments, but takes just 1
 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_begin, begin, true)
                                                         ^
In file included from /usr/include/boost/mpl/sequence_tag.hpp:18:0,
                 from /usr/include/boost/mpl/begin_end.hpp:19,
                 from /usr/include/boost/mpl/iter_fold.hpp:18,
                 from /usr/include/boost/variant/detail/initializer.hpp:28,
                 from /usr/include/boost/variant/variant.hpp:31,
                 from /usr/include/boost/variant.hpp:17,
                 from /usr/include/cppconn/connection.h:31,
                 from /usr/include/cppconn/driver.h:30,
                 from /usr/include/mysql_driver.h:32,
                 from src/test_mariadb.cpp:3:
/usr/include/boost/mpl/aux_/has_tag.hpp:20:54: error: macro "test" passed 2 arguments, but takes just 1
 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_tag, tag, false)
                                                      ^
In file included from /usr/include/boost/mpl/aux_/O1_size_impl.hpp:20:0,
                 from /usr/include/boost/mpl/O1_size.hpp:19,
                 from /usr/include/boost/mpl/iter_fold.hpp:19,
                 from /usr/include/boost/variant/detail/initializer.hpp:28,
                 from /usr/include/boost/variant/variant.hpp:31,
                 from /usr/include/boost/variant.hpp:17,
                 from /usr/include/cppconn/connection.h:31,
                 from /usr/include/cppconn/driver.h:30,
                 from /usr/include/mysql_driver.h:32,
                 from src/test_mariadb.cpp:3:
/usr/include/boost/mpl/aux_/has_size.hpp:20:1: error: macro "test" passed 2 arguments, but takes just 1
 BOOST_MPL_HAS_XXX_TRAIT_DEF(size)
 ^
In file included from /usr/include/boost/mpl/apply_wrap.hpp:23:0,
                 from /usr/include/boost/mpl/bind.hpp:27,
                 from /usr/include/boost/mpl/lambda.hpp:18,
                 from /usr/include/boost/mpl/iter_fold.hpp:20,
                 from /usr/include/boost/variant/detail/initializer.hpp:28,
                 from /usr/include/boost/variant/variant.hpp:31,
                 from /usr/include/boost/variant.hpp:17,
                 from /usr/include/cppconn/connection.h:31,
                 from /usr/include/cppconn/driver.h:30,
                 from /usr/include/mysql_driver.h:32,
                 from src/test_mariadb.cpp:3:
/usr/include/boost/mpl/aux_/has_apply.hpp:22:58: error: macro "test" passed 2 arguments, but takes just 1
 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_apply, apply, false)
                                                          ^
In file included from /usr/include/boost/mpl/quote.hpp:23:0,
                 from /usr/include/boost/mpl/aux_/full_lambda.hpp:25,
                 from /usr/include/boost/mpl/lambda.hpp:22,
                 from /usr/include/boost/mpl/iter_fold.hpp:20,
                 from /usr/include/boost/variant/detail/initializer.hpp:28,
                 from /usr/include/boost/variant/variant.hpp:31,
                 from /usr/include/boost/variant.hpp:17,
                 from /usr/include/cppconn/connection.h:31,
                 from /usr/include/cppconn/driver.h:30,
                 from /usr/include/mysql_driver.h:32,
                 from src/test_mariadb.cpp:3:
/usr/include/boost/mpl/aux_/has_type.hpp:20:55: error: macro "test" passed 2 arguments, but takes just 1
 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_type, type, true)
                                                       ^
In file included from src/test_mariadb.cpp:1:0:
/usr/include/c++/4.8/bits/stl_algobase.h:193:5: error: expected unqualified-id before ‘const’
     min(const _Tp& __a, const _Tp& __b)
     ^
/usr/include/c++/4.8/bits/stl_algobase.h:193:5: error: expected ‘)’ before ‘const’
/usr/include/c++/4.8/bits/stl_algobase.h:193:5: error: expected ‘)’ before ‘const’
/usr/include/c++/4.8/bits/stl_algobase.h:193:5: error: expected initializer before ‘const’
/usr/include/c++/4.8/bits/stl_algobase.h:216:5: error: expected unqualified-id before ‘const’
     max(const _Tp& __a, const _Tp& __b)
     ^
/usr/include/c++/4.8/bits/stl_algobase.h:216:5: error: expected ‘)’ before ‘const’
/usr/include/c++/4.8/bits/stl_algobase.h:216:5: error: expected ‘)’ before ‘const’
/usr/include/c++/4.8/bits/stl_algobase.h:216:5: error: expected initializer before ‘const’
In file included from /usr/include/c++/4.8/bits/char_traits.h:39:0,
                 from /usr/include/c++/4.8/ios:40,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from /usr/include/boost/assert.hpp:82,
                 from /usr/include/boost/smart_ptr/scoped_ptr.hpp:15,
                 from /usr/include/boost/scoped_ptr.hpp:14,
                 from /usr/include/mysql_driver.h:30,
                 from src/test_mariadb.cpp:3:
/usr/include/c++/4.8/bits/stl_algobase.h:239:5: error: ‘std::min’ declared as an ‘inline’ variable
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^
/usr/include/c++/4.8/bits/stl_algobase.h:239:5: error: template declaration of ‘const _Tp& std::min’
/usr/include/c++/4.8/bits/stl_algobase.h:242:7: error: expected primary-expression before ‘if’
       if (__comp(__b, __a))
       ^
/usr/include/c++/4.8/bits/stl_algobase.h:242:7: error: expected ‘}’ before ‘if’
/usr/include/c++/4.8/bits/stl_algobase.h:244:7: error: expected unqualified-id before ‘return’
       return __a;
       ^
/usr/include/c++/4.8/bits/stl_algobase.h:260:5: error: ‘max’ declared as an ‘inline’ variable
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^
/usr/include/c++/4.8/bits/stl_algobase.h:260:5: error: template declaration of ‘const _Tp& max’
/usr/include/c++/4.8/bits/stl_algobase.h:263:7: error: expected primary-expression before ‘if’
       if (__comp(__a, __b))
       ^
/usr/include/c++/4.8/bits/stl_algobase.h:263:7: error: expected ‘}’ before ‘if’
/usr/include/c++/4.8/bits/stl_algobase.h:265:7: error: expected unqualified-id before ‘return’
       return __a;
       ^
/usr/include/c++/4.8/bits/stl_algobase.h:266:5: error: expected declaration before ‘}’ token
     }

Upvotes: 1

Views: 1600

Answers (1)

softwariness
softwariness

Reputation: 4052

A header you have included has defined preprocessor macros named min, max and test. These have then conflicted with identifiers used (e.g. for method names) in other header files you have included.

Assuming that those macros have been defined in one of these headers:

#include <my_global.h>
#include <mysql.h>

you could add #undefs before you include mysql_driver.h, e.g.:

#include <my_global.h>
#include <mysql.h>
#undef min
#undef max
#undef test
#include "mysql_driver.h"

You could also consider re-arranging the order in which you include the files, or look into what headers are defining these and see whether the definition of these macros can be disabled.

Upvotes: 1

Related Questions