Comments (5)
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)
from sqlpp11-connector-mysql.
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
from sqlpp11-connector-mysql.
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?
from sqlpp11-connector-mysql.
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
.
from sqlpp11-connector-mysql.
Solved as commented on gitter
from sqlpp11-connector-mysql.
Related Issues (20)
- Data is truncated with MariaDB Connector/C 3.0.1+ HOT 11
- Selecting a datetime field always returns epoch HOT 2
- Microseconds ignored when selecting datetime column HOT 1
- Mac osX build HOT 8
- Crash of queries due to MYSQL_RES that is NULL HOT 7
- mysql replace into command HOT 5
- how to use unhex function ,could you give some info? HOT 1
- database name not used HOT 2
- sample code does not work on windows HOT 1
- Can't build DLL on windows HOT 2
- {char,bind}_result_t.size() is unimplemented HOT 5
- How to create mysql::connection without config HOT 2
- TLS/SSL connection is unsupported HOT 1
- Does sqlpp11 support a connection pool? What do I need to do? HOT 2
- How to return mysql auto incorrect when inserting a record in the table? HOT 2
- how can I set mysql options HOT 1
- Error reported while installing sqlpp11-mysql HOT 4
- Why is it necessary to pass database parameter when creating a connection? HOT 3
- Error when compiling HOT 5
- build failed on linux HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlpp11-connector-mysql.