[odb-users] Compile Problem with odd and mysql

Tschoche.Jonas at ddv-mediengruppe.de Tschoche.Jonas at ddv-mediengruppe.de
Tue Oct 15 15:17:49 EDT 2019


Hello,

i have a problem with odb. I compiled all components with build2 on MacOS Mojave
(odb, libodb, libodb-mysql, libodb-sqlite, libodb-boost, …).

I tried to compile an example with odb with following command:

odb -d mysql --generate-query --generate-schema --schema-format embedded --std c++11 --output-dir /Users /DEV/Examples/OdbCmake/cmake-build-debug/odb_gen --hxx-suffix .h --ixx-suffix _inline.h --cxx-suffix .cpp --odb-file-suffix _odb -I/usr/local/include -I/usr/local/Cellar/mysql-connector-c/6.1.11/include -I/usr/local/include/odb/mysql person.h

It working, but when I compile the project with CMAKE (example from github: https://github.com/BtbN/OdbCmake/) then I get a compile error:

In file included from /Users/DEV/Examples/OdbCmake/cmake-build-debug/odb_gen/person_odb.cpp:9:
In file included from /Users/DEV/Examples/OdbCmake/cmake-build-debug/odb_gen/person_odb.h:107:
/usr/local/include/odb/mysql/binding.hxx:28:16: error: unknown type name 'MYSQL_BIND'; did you mean 'MYSQL_TIME'?
      binding (MYSQL_BIND* b, std::size_t n)
               ^
/usr/local/include/mysql/mysql_time.h:69:3: note: 'MYSQL_TIME' declared here
} MYSQL_TIME;
  ^
In file included from /Users/DEV/Examples/OdbCmake/cmake-build-debug/odb_gen/person_odb.cpp:9:
In file included from /Users/DEV/Examples/OdbCmake/cmake-build-debug/odb_gen/person_odb.h:107:
/usr/local/include/odb/mysql/binding.hxx:33:7: error: unknown type name 'MYSQL_BIND'; did you mean 'MYSQL_TIME'?
      MYSQL_BIND* bind;
      ^
/usr/local/include/mysql/mysql_time.h:69:3: note: 'MYSQL_TIME' declared here
} MYSQL_TIME;
  ^
I had include the mysql libs, but the compiler don’t know “mysql”.

My CMAKE file:

cmake_minimum_required(VERSION 2.8.12)

project(OdbCMake)

set(CMAKE_EXE_LINKER_FLAGS -all_load) # macos

set(CMAKE_VERBOSE_MAKEFILE ON)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")

set(MYSQL_FIND_QUIETLY OFF )
find_package(MySQL)
find_package(SQLite3)
find_package(ODB REQUIRED COMPONENTS sqlite mysql OPTIONAL_COMPONENTS pgsql)
include(${ODB_USE_FILE})

set(OdbCMake_SOURCES
   driver.cpp
   database.h)

set(OdbCMake_ODB_HEADERS
   person.h)

set(ODB_COMPILE_DEBUG ON)
odb_compile(OdbCMake_SOURCES FILES ${OdbCMake_ODB_HEADERS} DB mysql GENERATE_QUERY GENERATE_SCHEMA SCHEMA_FORMAT embedded STANDARD c++11 INCLUDE  ${ODB_INCLUDE_DIRS}  ${MYSQL_INCLUDE_DIR}  ${ODB_MYSQL_INCLUDE_DIRS}/odb/mysql)

message("ODB_INCLUDE_DIRS: ${ODB_INCLUDE_DIRS}")
message("OUTPUT: ${ODB_COMPILE_OUTPUT_DIR}")
message("")
message("MYSQL_LIB: ${MYSQL_LIBRARIES}")
message("MySQL_INCLUDE_DIRS: ${MYSQL_INCLUDE_DIR}")
message("")
message("MYSQL_LIB (ODB): ${ODB_MYSQL_LIBRARIES}")
message("MySQL_INCLUDE_DIRS (ODB): ${ODB_MYSQL_INCLUDE_DIRS}")
message("")
message("MYSQL_LIB: ${MYSQL_LIBRARIES}")
message("MySQL_INCLUDE_DIRS: ${MYSQL_INCLUDE_DIR}")
message("")
message("LIBSQLLITE: ${SQLite3_LIBRARIES}")
message("LIBSQLLITE_INCLUDE_DIRS: ${SQLite3_INCLUDE_DIRS}")
message("ODB:")
message(${OdbCMake_ODB_HEADERS})

add_executable(odbcmake
   ${OdbCMake_SOURCES}
   ${OdbCMake_ODB_HEADERS})

target_link_libraries(odbcmake
      ${MYSQL_LIBRARIES}
      ${ODB_LIBRARIES}
      ${ODB_MYSQL_LIBRARIES}
   )

target_include_directories(odbcmake
   PUBLIC
      ${MYSQL_INCLUDE_DIR}
   PRIVATE
      ${ODB_INCLUDE_DIRS}
      ${ODB_MYSQL_INCLUDE_DIRS}
      ${ODB_COMPILE_OUTPUT_DIR}
)

target_compile_definitions(odbcmake
   PRIVATE
      DATABASE_MYSQL)

The Source Files are from Github: https://github.com/BtbN/OdbCmake/


---
When I try to compile the official example then I get also a build error:

Making all in access
/Applications/Xcode.app/Contents/Developer/usr/bin/make  all-am
depbase=`echo driver.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
                g++ -DHAVE_CONFIG_H   -I'.' -I'.'  -DDATABASE_SQLITE    -I/usr/local/include  -g -O2 -D_THREAD_SAFE  -MT driver.o -MD -MP -MF $depbase.Tpo -c -o driver.o driver.cxx &&\
                mv -f $depbase.Tpo $depbase.Po
In file included from driver.cxx:7:
In file included from /usr/local/include/odb/database.hxx:23:
/usr/local/include/odb/traits.hxx:138:22: error: implicit instantiation of undefined template 'odb::pointer_traits<std::__1::shared_ptr<person> >'
    typedef typename pointer_traits::const_pointer_type const_pointer_type;
                     ^
/usr/local/include/odb/database.ixx:160:19: note: in instantiation of template class 'odb::object_traits<person>' requested here
  inline typename object_traits<T>::id_type database::
                  ^
driver.cxx:30:11: note: while substituting deduced template arguments into function template 'persist' [with T = person]
      db->persist (john);
          ^
/usr/local/include/odb/pointer-traits.hxx:28:9: note: template is declared here
  class pointer_traits;
        ^
driver.cxx:39:21: warning: lookup of 'query' in member access expression is ambiguous; using member of 'odb::database' [-Wambiguous-member-template]
      result r (db->query<person> ());
                    ^
/usr/local/include/odb/database.ixx:557:3: note: lookup in the object type 'odb::database' refers here
  query (bool cache)
  ^
/usr/local/include/odb/query.hxx:110:9: note: lookup from the current scope refers here
  class query;
        ^
In file included from driver.cxx:13:
In file included from ./person-odb.hxx:32:
/usr/local/include/odb/simple-object-result.hxx:149:14: error: implicit instantiation of undefined template 'odb::pointer_traits<std::__1::shared_ptr<person> >'
    typename pointer_traits::guard guard_;
             ^
/usr/local/include/odb/details/shared-ptr/base.txx:58:53: note: in instantiation of template class 'odb::object_result_impl<person>' requested here
                std::size_t A = sizeof (bits::test (reinterpret_cast<X*> (0)))>
                                                    ^
/usr/local/include/odb/details/shared-ptr.hxx:20:48: note: in instantiation of default argument for 'counter_type<odb::object_result_impl<person> >' required here
      private bits::counter_ops<typename bits::counter_type<X>::r, X>
                                               ^~~~~~~~~~~~~~~
/usr/local/include/odb/result.hxx:234:43: note: in instantiation of template class 'odb::details::shared_ptr<odb::object_result_impl<person> >' requested here
    details::shared_ptr<result_impl_type> impl_;
                                          ^
driver.cxx:39:21: note: in instantiation of template class 'odb::result<person>' requested here
      result r (db->query<person> ());
                    ^
/usr/local/include/odb/pointer-traits.hxx:28:9: note: template is declared here
  class pointer_traits;
        ^
In file included from driver.cxx:7:
In file included from /usr/local/include/odb/database.hxx:27:
In file included from /usr/local/include/odb/prepared-query.hxx:12:
In file included from /usr/local/include/odb/result.hxx:16:
In file included from /usr/local/include/odb/details/shared-ptr.hxx:11:
In file included from /usr/local/include/odb/details/shared-ptr/base.hxx:128:
/usr/local/include/odb/details/shared-ptr/base.txx:58:53: error: cannot initialize a parameter of type 'odb::details::shared_base *' with an rvalue of type 'odb::object_result_impl<person> *'
                std::size_t A = sizeof (bits::test (reinterpret_cast<X*> (0)))>
                                                    ^~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/odb/details/shared-ptr.hxx:20:48: note: in instantiation of default argument for 'counter_type<odb::object_result_impl<person> >' required here
      private bits::counter_ops<typename bits::counter_type<X>::r, X>
                                               ^~~~~~~~~~~~~~~
/usr/local/include/odb/result.hxx:234:43: note: in instantiation of template class 'odb::details::shared_ptr<odb::object_result_impl<person> >' requested here
    details::shared_ptr<result_impl_type> impl_;
                                          ^
driver.cxx:39:21: note: in instantiation of template class 'odb::result<person>' requested here
      result r (db->query<person> ());
                    ^
/usr/local/include/odb/details/shared-ptr/base.txx:55:35: note: passing argument to parameter here
      meta::yes test (shared_base*);
                                  ^
In file included from driver.cxx:7:
In file included from /usr/local/include/odb/database.hxx:23:
/usr/local/include/odb/traits.hxx:158:22: error: implicit instantiation of undefined template 'odb::pointer_traits<std::__1::shared_ptr<person> >'
    typedef typename pointer_traits::const_pointer_type const_pointer_type;
                     ^
/usr/local/include/odb/database.hxx:537:5: note: in instantiation of template class 'odb::object_traits<const person>' requested here
    typename object_traits<T>::id_type
    ^
/usr/local/include/odb/database.ixx:170:12: note: while substituting explicitly-specified template arguments into function template 'persist_'
    return persist_<const T, id_common> (obj);
           ^
driver.cxx:30:11: note: in instantiation of function template specialization 'odb::database::persist<person>' requested here
      db->persist (john);
          ^
/usr/local/include/odb/pointer-traits.hxx:28:9: note: template is declared here
  class pointer_traits;
        ^
In file included from driver.cxx:7:
In file included from /usr/local/include/odb/database.hxx:651:
/usr/local/include/odb/database.ixx:170:12: error: no matching member function for call to 'persist_'
    return persist_<const T, id_common> (obj);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
driver.cxx:30:11: note: in instantiation of function template specialization 'odb::database::persist<person>' requested here
      db->persist (john);
          ^
/usr/local/include/odb/database.hxx:542:5: note: candidate function template not viable: no known conversion from 'const person' to 'const typename object_traits<const person>::pointer_type' (aka 'const int') for 1st argument
    persist_ (const typename object_traits<T>::pointer_type&);
    ^
/usr/local/include/odb/database.hxx:538:5: note: candidate template ignored: substitution failure [with T = const person, DB = odb::id_common]
    persist_ (T&);
    ^
/usr/local/include/odb/database.hxx:546:5: note: candidate function template not viable: requires 3 arguments, but 1 was provided
    persist_ (I, I, bool);
    ^
/usr/local/include/odb/database.hxx:550:5: note: candidate function template not viable: requires 4 arguments, but 1 was provided
    persist_ (I, I, bool, details::meta::no ptr);
    ^
/usr/local/include/odb/database.hxx:554:5: note: candidate function template not viable: requires 4 arguments, but 1 was provided
    persist_ (I, I, bool, details::meta::yes ptr);
    ^
In file included from driver.cxx:7:
In file included from /usr/local/include/odb/database.hxx:23:
/usr/local/include/odb/traits.hxx:187:22: error: implicit instantiation of undefined template 'odb::pointer_traits<std::__1::shared_ptr<person> >'
    typedef typename pointer_traits::const_pointer_type const_pointer_type;
                     ^
/usr/local/include/odb/database.txx:38:5: note: in instantiation of template class 'odb::object_traits_impl<person, odb::id_common>' requested here
    object_traits::persist (*this, obj);
    ^
/usr/local/include/odb/database.ixx:163:12: note: in instantiation of function template specialization 'odb::database::persist_<person, odb::id_common>' requested here
    return persist_<T, id_common> (obj);
           ^
driver.cxx:31:11: note: in instantiation of function template specialization 'odb::database::persist<person>' requested here
      db->persist (jane);
          ^
/usr/local/include/odb/pointer-traits.hxx:28:9: note: template is declared here
  class pointer_traits;
        ^
In file included from driver.cxx:7:
In file included from /usr/local/include/odb/database.hxx:652:
/usr/local/include/odb/database.txx:38:18: error: incomplete definition of type 'odb::object_traits_impl<person, odb::id_common>'
    object_traits::persist (*this, obj);
    ~~~~~~~~~~~~~^~
/usr/local/include/odb/database.ixx:163:12: note: in instantiation of function template specialization 'odb::database::persist_<person, odb::id_common>' requested here
    return persist_<T, id_common> (obj);
           ^
driver.cxx:31:11: note: in instantiation of function template specialization 'odb::database::persist<person>' requested here
      db->persist (jane);
          ^
In file included from driver.cxx:7:
In file included from /usr/local/include/odb/database.hxx:23:
/usr/local/include/odb/traits.hxx:187:22: error: implicit instantiation of undefined template 'odb::pointer_traits<std::__1::shared_ptr<person> >'
    typedef typename pointer_traits::const_pointer_type const_pointer_type;
                     ^
/usr/local/include/odb/query.hxx:89:22: note: in instantiation of template class 'odb::object_traits_impl<person, odb::id_sqlite>' requested here
    typedef typename object_traits_impl<T, DB>::query_base_type base_type;
                     ^
/usr/local/include/odb/query.hxx:104:26: note: in instantiation of template class 'odb::query_selector_impl<person, odb::id_sqlite, odb::class_object>' requested here
  struct query_selector: query_selector_impl<T, DB, class_traits<T>::kind>
                         ^
/usr/local/include/odb/sqlite/query.hxx:1597:25: note: in instantiation of template class 'odb::query_selector<person, odb::id_sqlite>' requested here
                 public query_selector<T, id_sqlite>::columns_type
                        ^
/usr/local/include/odb/sqlite/query.hxx:1667:46: note: in instantiation of template class 'odb::sqlite::query<person>' requested here
  class query<T, sqlite::query_base>: public sqlite::query<T>
                                             ^
/usr/local/include/odb/database.ixx:559:22: note: in instantiation of template class 'odb::query<person, odb::sqlite::query_base>' requested here
    return query<T> (odb::query<T> (), cache);
                     ^
driver.cxx:39:21: note: in instantiation of function template specialization 'odb::database::query<person>' requested here
      result r (db->query<person> ());
                    ^
/usr/local/include/odb/pointer-traits.hxx:28:9: note: template is declared here
  class pointer_traits;
        ^
In file included from driver.cxx:13:
In file included from ./person-odb.hxx:32:
In file included from /usr/local/include/odb/simple-object-result.hxx:16:
/usr/local/include/odb/object-result.hxx:108:14: error: implicit instantiation of undefined template 'odb::pointer_traits<std::__1::shared_ptr<person> >'
      return pointer_traits::get_ptr (this->res_->current ());
             ^
driver.cxx:42:18: note: in instantiation of member function 'odb::result_iterator<person, odb::class_object>::operator->' requested here
        cout << i->getFirst () << ' '
                 ^
/usr/local/include/odb/pointer-traits.hxx:28:9: note: template is declared here
  class pointer_traits;
        ^
In file included from driver.cxx:13:
In file included from ./person-odb.hxx:32:
In file included from /usr/local/include/odb/simple-object-result.hxx:16:
/usr/local/include/odb/object-result.hxx:108:28: error: incomplete definition of type 'odb::pointer_traits<std::__1::shared_ptr<person> >'
      return pointer_traits::get_ptr (this->res_->current ());
             ~~~~~~~~~~~~~~^~
1 warning and 10 errors generated.
make[3]: *** [driver.o] Error 1
make[2]: *** [all] Error 2
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

I configured with:

 ./configure  --with-database=sqlite CPPFLAGS=-I/usr/local/include LDFLAGS=-L/opt/local/lib ODBCPPFLAGS="-I/usr/local/include"



More information about the odb-users mailing list