Skip to content
This repository has been archived by the owner on Dec 18, 2021. It is now read-only.

Installation/Include Issues #22

Closed
andystroz opened this issue Mar 8, 2017 · 5 comments
Closed

Installation/Include Issues #22

andystroz opened this issue Mar 8, 2017 · 5 comments

Comments

@andystroz
Copy link

How is this installed using CMake along side sqlpp11. I have sqlpp11 installed using the process described on the README on that github page but I am unable to install this project as I get the errors...

-- Using /usr/bin/c++ (compiler id: GNU)
CMake Error at CMakeLists.txt:46 (message):
  Can't find file date.h


Can't find date.h in /home/andrew/cpp_work/sqlpp11_libs/sqlpp11-connector-mysql/../date 
Please either
  - git clone https://github.com/howardhinnant/date /home/andrew/cpp_work/sqlpp11_libs/sqlpp11-connector-mysql/../date
  - download and unzip a current version from https://github.com/howardhinnant/date to /home/andrew/cpp_work/sqlpp11_libs/sqlpp11-connector-mysql/../date
  - set DATE_INCLUDE_DIR to point to the dir containing date.h from the date library

CMake Error at CMakeLists.txt:60 (message):
  Can't find file sqlpp11/sqlpp11.h


Can't find sqlpp11/sqlpp11.h in /home/andrew/cpp_work/sqlpp11_libs/sqlpp11-connector-mysql/../sqlpp11/include 
Please either
  - git clone https://github.com/rbock/sqlpp11 /home/andrew/cpp_work/sqlpp11_libs/sqlpp11-connector-mysql/../sqlpp11/include
  - download and unzip a current version from https://github.com/rbock/sqlpp11 to /home/andrew/cpp_work/sqlpp11_libs/sqlpp11-connector-mysql/../sqlpp11/include
  - set DATE_INCLUDE_DIR to point to the dir containing sqlpp11/sqlpp11.h

-- Configuring incomplete, errors occurred!
See also "/home/andrew/cpp_work/sqlpp11_libs/sqlpp11-connector-mysql/build/CMakeFiles/CMakeOutput.log".
See also "/home/andrew/cpp_work/sqlpp11_libs/sqlpp11-connector-mysql/build/CMakeFiles/CMakeError.log".
@andystroz
Copy link
Author

andystroz commented Mar 8, 2017

I managed to get the above working, my issue was that I was not installing properly. I now get the following error from this code.

main.cpp:(.text+0x124): undefined reference to `sqlpp::mysql::connection::connection(std::shared_ptr<sqlpp::mysql::con
nection_config> const&)'                                                                                              
main.cpp:(.text+0x12e): undefined reference to `sqlpp::mysql::connection::~connection()'                              
collect2: error: ld returned 1 exit status                                                                            
CMakeFiles/mysql_sample.dir/build.make:94: recipe for target 'mysql_sample' failed                                    
make[2]: *** [mysql_sample] Error 1                                                                                   
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/mysql_sample.dir/all' failed                                   
make[1]: *** [CMakeFiles/mysql_sample.dir/all] Error 2                                                                
Makefile:83: recipe for target 'all' failed                                                                           
make: *** [all] Error 2                                                                                               

Code:

include "TabSample.h"
#include <sqlpp11/sqlpp11.h>
#include <sqlpp11/mysql/mysql.h>

namespace mysql = sqlpp::mysql;
int main()
{
    auto config = std::make_shared<mysql::connection_config>();
    config->user = "root";
    config->database = "sqlpp_mysql";
    config->debug = true;
    mysql::connection db(config);

    TabSample tab;
    for(const auto& row : db.run(sqlpp::select(all_of(tab)).from(tab).unconditionally()))
    {
        std::cerr << "row.alpha: " << row.alpha << ", row.beta: " << row.beta << ", row.gamma: " << row.gamma <<  std::endl;
    };
  return 0;
}

I am using gcc 4.9 and there are no errors with the make / make install, am I missing something in my CMakeLists.txt?

cmake_minimum_required(VERSION 3.5)
project(mysql_sample)

set(HinnantDate_ROOT_DIR "/usr/local/lib/date")
include_directories(/usr/local/lib/date)
if(UNIX)
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=gnu++0x")
endif()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/CMake)

set(SQLPP11_INCLUDE_DIR /usr/local/include)

find_package(Sqlpp11 REQUIRED)

add_executable(mysql_sample src/main.cpp)

target_link_libraries(mysql_sample ${sqlpp11_LIBRARIES})
target_link_libraries(mysql_sample ${sqlpp11-connector-mysql_LIBRARIES})

include_directories(${PROJECT_SOURCE_DIR}/include)

add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(test)

@rbock
Copy link
Owner

rbock commented Mar 8, 2017

Hi,

can you check if ${sqlpp11-connector-mysql_LIBRARIES} is actually set to anything?

As of now, there is no find_package support for the connector library yet (maybe you could help with that?). You have to set the library by hand.

HTH

Best,

Roland

@andystroz
Copy link
Author

andystroz commented Mar 9, 2017

That was my issue I am now able to find the library and the project works on the Debian machine I am working on but it does not work on the Ubuntu one.

The Ubuntu one throws the following error when compiling with gcc 4.9.3 or 5.6 using mysql v5.7.

[ 50%] Linking CXX executable mysql_sample
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::(anonymous namespace)::MySqlThreadInitializer::MySqlThreadInitializer()':
connection.cpp:(.text+0xae): undefined reference to `mysql_thread_safe'
connection.cpp:(.text+0xe8): undefined reference to `mysql_thread_init'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::(anonymous namespace)::MySqlThreadInitializer::~MySqlThreadInitializer()':
connection.cpp:(.text+0x11b): undefined reference to `mysql_thread_end'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::(anonymous namespace)::execute_statement(sqlpp::mysql::detail::connection_handle_t&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
connection.cpp:(.text+0x23d): undefined reference to `mysql_query'
connection.cpp:(.text+0x281): undefined reference to `mysql_error'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::(anonymous namespace)::execute_prepared_statement(sqlpp::mysql::detail::prepared_statement_handle_t&)':
connection.cpp:(.text+0x48b): undefined reference to `mysql_stmt_bind_param'
connection.cpp:(.text+0x4b4): undefined reference to `mysql_stmt_error'
connection.cpp:(.text+0x542): undefined reference to `mysql_stmt_execute'
connection.cpp:(.text+0x56b): undefined reference to `mysql_stmt_error'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::(anonymous namespace)::prepare_statement(sqlpp::mysql::detail::connection_handle_t&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, unsigned long)':
connection.cpp:(.text+0x768): undefined reference to `mysql_stmt_init'
connection.cpp:(.text+0x81c): undefined reference to `mysql_stmt_prepare'
connection.cpp:(.text+0x860): undefined reference to `mysql_error'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::connection::connection(std::shared_ptr<sqlpp::mysql::connection_config> const&)':
connection.cpp:(.text+0xae7): undefined reference to `mysql_set_character_set'
connection.cpp:(.text+0xba5): undefined reference to `mysql_select_db'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::connection::select_impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
connection.cpp:(.text+0xdd7): undefined reference to `mysql_store_result'
connection.cpp:(.text+0xe7c): undefined reference to `mysql_error'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::connection::run_prepared_insert_impl(sqlpp::mysql::prepared_statement_t&)':
connection.cpp:(.text+0x1025): undefined reference to `mysql_stmt_insert_id'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::connection::run_prepared_update_impl(sqlpp::mysql::prepared_statement_t&)':
connection.cpp:(.text+0x1063): undefined reference to `mysql_stmt_affected_rows'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::connection::run_prepared_remove_impl(sqlpp::mysql::prepared_statement_t&)':
connection.cpp:(.text+0x10a1): undefined reference to `mysql_stmt_affected_rows'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::connection::insert_impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
connection.cpp:(.text+0x11a8): undefined reference to `mysql_insert_id'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::connection::update_impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
connection.cpp:(.text+0x122a): undefined reference to `mysql_affected_rows'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::connection::remove_impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
connection.cpp:(.text+0x127a): undefined reference to `mysql_affected_rows'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::connection::escape(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const':
connection.cpp:(.text+0x1327): undefined reference to `mysql_real_escape_string'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::detail::prepared_statement_handle_t::~prepared_statement_handle_t()':
connection.cpp:(.text._ZN5sqlpp5mysql6detail27prepared_statement_handle_tD2Ev[_ZN5sqlpp5mysql6detail27prepared_statement_handle_tD5Ev]+0x23): undefined reference to `mysql_stmt_close'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::detail::result_handle::~result_handle()':
connection.cpp:(.text._ZN5sqlpp5mysql6detail13result_handleD2Ev[_ZN5sqlpp5mysql6detail13result_handleD5Ev]+0x23): undefined reference to `mysql_free_result'
//usr/local/lib/libsqlpp-mysql.a(char_result.cpp.o): In function `sqlpp::mysql::char_result_t::next_impl()':
char_result.cpp:(.text+0x944): undefined reference to `mysql_fetch_row'
char_result.cpp:(.text+0x966): undefined reference to `mysql_fetch_lengths'
//usr/local/lib/libsqlpp-mysql.a(bind_result.cpp.o): In function `sqlpp::mysql::bind_result_t::bind_impl()':
bind_result.cpp:(.text+0xf62): undefined reference to `mysql_stmt_bind_result'
bind_result.cpp:(.text+0xf93): undefined reference to `mysql_stmt_error'
//usr/local/lib/libsqlpp-mysql.a(bind_result.cpp.o): In function `sqlpp::mysql::bind_result_t::next_impl()':
bind_result.cpp:(.text+0x110b): undefined reference to `mysql_stmt_fetch'
bind_result.cpp:(.text+0x1375): undefined reference to `mysql_stmt_fetch_column'
bind_result.cpp:(.text+0x13a9): undefined reference to `mysql_stmt_error'
bind_result.cpp:(.text+0x14e0): undefined reference to `mysql_stmt_error'
//usr/local/lib/libsqlpp-mysql.a(connection_handle.cpp.o): In function `sqlpp::mysql::detail::connection_handle_t::connection_handle_t(std::shared_ptr<sqlpp::mysql::connection_config> const&)':
connection_handle.cpp:(.text+0x19c): undefined reference to `mysql_init'
connection_handle.cpp:(.text+0x220): undefined reference to `mysql_options'
connection_handle.cpp:(.text+0x3ce): undefined reference to `mysql_real_connect'
connection_handle.cpp:(.text+0x417): undefined reference to `mysql_error'
//usr/local/lib/libsqlpp-mysql.a(connection_handle.cpp.o): In function `sqlpp::mysql::detail::connection_handle_t::~connection_handle_t()':
connection_handle.cpp:(.text+0x56c): undefined reference to `mysql_close'
collect2: error: ld returned 1 exit status
CMakeFiles/mysql_sample.dir/build.make:94: recipe for target 'mysql_sample' failed
make[2]: *** [mysql_sample] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/mysql_sample.dir/all' failed
make[1]: *** [CMakeFiles/mysql_sample.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

I am going to try using gcc 4.9.2 later this afternoon but I do not think this is the problem. Could it be the version of SQL I am using?

@rbock
Copy link
Owner

rbock commented Mar 9, 2017

This is a link-time problem. For some reason, you're not linking against the mysql/mariadb library. Check your commands, e.g. by running make VERBOSE=1.

@rbock
Copy link
Owner

rbock commented Mar 19, 2017

Solved as commented on gitter

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants