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

undefined reference to `mysql_thread_safe' #32

Closed
olegabr opened this issue Nov 18, 2017 · 3 comments
Closed

undefined reference to `mysql_thread_safe' #32

olegabr opened this issue Nov 18, 2017 · 3 comments

Comments

@olegabr
Copy link

olegabr commented Nov 18, 2017

I have the same issue as mentioned here: #22 (comment)

Since there is no solution provided in the link above, any help would be appreciated.

I have this libs installed on ubuntu 16.04:

dpkg -l|grep mysql
ii  libmysqlclient-dev          5.7.20-0ubuntu0.16.04.1               amd64        MySQL database development files
ii  libmysqlclient20:amd64      5.7.20-0ubuntu0.16.04.1               amd64        MySQL database client library
ii  libmysqlcppconn-dev         1.1.7-0ubuntu1                        amd64        MySQL Connector for C++ (development files)
ii  libmysqlcppconn7v5          1.1.7-0ubuntu1                        amd64        MySQL Connector for C++ (library)
ii  mysql-common                5.7.20-0ubuntu0.16.04.1               all          MySQL database common files, e.g. /etc/mysql/my.cnf
cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04 LTS"

The full error log:

/usr/bin/c++   -std=c++11 -w -Wno-unknown-pragmas -Wno-sign-compare -Woverloaded-virtual -Wwrite-strings -Wno-unused -O3 -fopenmp  -rdynamic CMakeFiles/tep.dir/TEP/TEP2/main.cpp.o  -o tep -Wl,-rpath,/build/nomos-c/build:/usr/local/lib -lpthread nomos-c/build/libnomos-c.so -lmysqlclient /usr/local/lib/liblog4cpp.so /usr/local/lib/libboost_thread.so /usr/local/lib/libboost_chrono.so /usr/local/lib/libboost_system.so /usr/local/lib/libboost_date_time.so /usr/local/lib/libboost_atomic.so /usr/local/lib/libcppnetlib-client-connections.a /usr/local/lib/libcppnetlib-server-parsers.a /usr/local/lib/libcppnetlib-uri.a -ltacopie -lcpp_redis -lmysqlclient -lsqlpp-mysql -lcurl -lpthread -lgsl -lblas -lrt -lpthread /usr/local/lib/libboost_thread.so /usr/local/lib/libboost_chrono.so /usr/local/lib/libboost_system.so /usr/local/lib/libboost_date_time.so /usr/local/lib/libboost_atomic.so -lssl -lcrypto 
//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/tep.dir/build.make:112: recipe for target 'tep' failed
make[2]: *** [tep] Error 1
make[2]: Leaving directory '/build'
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/tep.dir/all' failed
make[1]: Leaving directory '/build'
make[1]: *** [CMakeFiles/tep.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
@rbock
Copy link
Owner

rbock commented Nov 18, 2017

Hi Oleg,

This is a linker problem which is hard to debug from remote.

I assume you can compile the tests that come with the library?

If you run make VERBOSE=1 it will show you compile and link commands. That should give you some hints. Try to run those "manually", too. On my machine -lmysqlclient is sufficient.

Also, try some minimalist examples, not the whole machinery at once.

What I noticed in your compile/link command is that there is a lot of duplication. Maybe the linker gets confused?

Hope that helps. Let me know.

Best,

Roland

@olegabr
Copy link
Author

olegabr commented Nov 19, 2017

The problem was obvious: the mysqlclient should be mentioned AFTER sqlpp-mysql in target_link_libraries section of your CMakeLists.txt file. It is g++ requirement that libs should be listed in it's usage order. if lib A uses lib B, they should be listed as A B in linker command.
In this case it should look like: -lsqlpp-mysql -lmysqlclient.

@olegabr olegabr closed this as completed Nov 19, 2017
@rbock
Copy link
Owner

rbock commented Nov 19, 2017

Thanks for the update!

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