0


I am working with MySQL/C++ Connector.
I've tried the solution provided by 'd3l' in this question
Then I got this errors :

tester.cpp: In function ‘int main()’:
tester.cpp:12:20: warning: variable ‘con’ set but not used [-Wunused-but-set-variable]
   sql::Connection *con;
                    ^
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::affected_rows(st_mysql*)':
(.text+0x164): undefined reference to `mysql_affected_rows'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::autocommit(st_mysql*, char)':
(.text+0x18d): undefined reference to `mysql_autocommit'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::close(st_mysql*)':
(.text+0x1ac): undefined reference to `mysql_close'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::commit(st_mysql*)':
(.text+0x1ca): undefined reference to `mysql_commit'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::data_seek(st_mysql_res*, unsigned long long)':
(.text+0x1f3): undefined reference to `mysql_data_seek'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::debug(char const*)':
(.text+0x212): undefined reference to `mysql_debug'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::mysql_errno(st_mysql*)':
(.text+0x230): undefined reference to `mysql_errno'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::error(st_mysql*)':
(.text+0x24e): undefined reference to `mysql_error'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::fetch_field(st_mysql_res*)':
(.text+0x26c): undefined reference to `mysql_fetch_field'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::fetch_field_direct(st_mysql_res*, unsigned int)':
(.text+0x292): undefined reference to `mysql_fetch_field_direct'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::fetch_lengths(st_mysql_res*)':
(.text+0x2b0): undefined reference to `mysql_fetch_lengths'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::fetch_row(st_mysql_res*)':
(.text+0x2ce): undefined reference to `mysql_fetch_row'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::field_count(st_mysql*)':
(.text+0x2ec): undefined reference to `mysql_field_count'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::free_result(st_mysql_res*)':
(.text+0x30a): undefined reference to `mysql_free_result'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::get_client_version()':
(.text+0x31d): undefined reference to `mysql_get_client_version'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::get_server_info(st_mysql*)':
(.text+0x33c): undefined reference to `mysql_get_server_info'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::get_server_version(st_mysql*)':
(.text+0x35a): undefined reference to `mysql_get_server_version'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::info(st_mysql*)':
(.text+0x378): undefined reference to `mysql_info'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::init(st_mysql*)':
(.text+0x396): undefined reference to `mysql_init'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::library_init(int, char**, char**)':
(.text+0x3c4): undefined reference to `mysql_server_init'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::library_end()':
(.text+0x3d7): undefined reference to `mysql_server_end'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::more_results(st_mysql*)':
(.text+0x3f6): undefined reference to `mysql_more_results'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::next_result(st_mysql*)':
(.text+0x414): undefined reference to `mysql_next_result'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::num_fields(st_mysql_res*)':
(.text+0x432): undefined reference to `mysql_num_fields'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::num_rows(st_mysql_res*)':
(.text+0x450): undefined reference to `mysql_num_rows'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::options(st_mysql*, mysql_option, void const*)':
(.text+0x47e): undefined reference to `mysql_options'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::query(st_mysql*, char const*)':
(.text+0x4a7): undefined reference to `mysql_query'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::ping(st_mysql*)':
(.text+0x4c6): undefined reference to `mysql_ping'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::real_connect(st_mysql*, char const*, char const*, char const*, char const*, unsigned int, char const*, unsigned long)':
(.text+0x519): undefined reference to `mysql_real_connect'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::real_escape_string(st_mysql*, char*, char const*, unsigned long)':
(.text+0x550): undefined reference to `mysql_real_escape_string'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::real_query(st_mysql*, char const*, unsigned long)':
(.text+0x581): undefined reference to `mysql_real_query'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::rollback(st_mysql*)':
(.text+0x5a0): undefined reference to `mysql_rollback'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::sqlstate(st_mysql*)':
(.text+0x5be): undefined reference to `mysql_sqlstate'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::ssl_set(st_mysql*, char const*, char const*, char const*, char const*, char const*)':
(.text+0x603): undefined reference to `mysql_ssl_set'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::store_result(st_mysql*)':
(.text+0x622): undefined reference to `mysql_store_result'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::use_result(st_mysql*)':
(.text+0x640): undefined reference to `mysql_use_result'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::warning_count(st_mysql*)':
(.text+0x65e): undefined reference to `mysql_warning_count'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::stmt_affected_rows(st_mysql_stmt*)':
(.text+0x67c): undefined reference to `mysql_stmt_affected_rows'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::stmt_attr_set(st_mysql_stmt*, enum_stmt_attr_type, void const*)':
(.text+0x6aa): undefined reference to `mysql_stmt_attr_set'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::stmt_bind_param(st_mysql_stmt*, st_mysql_bind*)':
(.text+0x6d3): undefined reference to `mysql_stmt_bind_param'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::stmt_bind_result(st_mysql_stmt*, st_mysql_bind*)':
(.text+0x6fd): undefined reference to `mysql_stmt_bind_result'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::stmt_close(st_mysql_stmt*)':
(.text+0x71c): undefined reference to `mysql_stmt_close'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::stmt_data_seek(st_mysql_stmt*, unsigned long long)':
(.text+0x745): undefined reference to `mysql_stmt_data_seek'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::stmt_errno(st_mysql_stmt*)':
(.text+0x764): undefined reference to `mysql_stmt_errno'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::stmt_error(st_mysql_stmt*)':
(.text+0x782): undefined reference to `mysql_stmt_error'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::stmt_execute(st_mysql_stmt*)':
(.text+0x7a0): undefined reference to `mysql_stmt_execute'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::stmt_fetch(st_mysql_stmt*)':
(.text+0x7be): undefined reference to `mysql_stmt_fetch'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::stmt_field_count(st_mysql_stmt*)':
(.text+0x7dc): undefined reference to `mysql_stmt_field_count'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::stmt_init(st_mysql*)':
(.text+0x7fa): undefined reference to `mysql_stmt_init'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::stmt_num_rows(st_mysql_stmt*)':
(.text+0x818): undefined reference to `mysql_stmt_num_rows'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::stmt_param_count(st_mysql_stmt*)':
(.text+0x836): undefined reference to `mysql_stmt_param_count'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::stmt_prepare(st_mysql_stmt*, char const*, unsigned long)':
(.text+0x867): undefined reference to `mysql_stmt_prepare'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::stmt_result_metadata(st_mysql_stmt*)':
(.text+0x886): undefined reference to `mysql_stmt_result_metadata'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::stmt_send_long_data(st_mysql_stmt*, unsigned int, char const*, unsigned long)':
(.text+0x8ba): undefined reference to `mysql_stmt_send_long_data'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::stmt_sqlstate(st_mysql_stmt*)':
(.text+0x8d8): undefined reference to `mysql_stmt_sqlstate'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::stmt_store_result(st_mysql_stmt*)':
(.text+0x8f6): undefined reference to `mysql_stmt_store_result'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::thread_end()':
(.text+0x909): undefined reference to `mysql_thread_end'
/usr/lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::thread_init()':
(.text+0x91d): undefined reference to `mysql_thread_init'
collect2: error: ld returned 1 exit status

I am running Ubuntu 14.
Please help.

EDIT :
As 'mukunda' says :
"usually connector/c++ is already statically linked to libmysql, that's the default setting when building the source"

So I compile it with :

sudo g++ -Wall -I/usr/include/cppconn -o testapp tester.cpp

Then the errors is reduced to only :

tester.cpp: In function ‘int main()’:
tester.cpp:12:20: warning: variable ‘con’ set but not used [-Wunused-but-set-variable]
   sql::Connection *con;
                    ^
/tmp/ccSdYfYy.o: In function `main':
tester.cpp:(.text+0xa): undefined reference to `get_driver_instance'
collect2: error: ld returned 1 exit status

EDIT AGAIN :
This is the necessary steps to build this code :

#include <stdlib.h>
#include <iostream>
#include <mysql_connection.h>
#include <driver.h>
#include <exception.h>
#include <resultset.h>
#include <statement.h>

using namespace sql;
int main(void){
  sql::Driver *driver;
  sql::Connection *con;

  driver = get_driver_instance();
  con = driver->connect("tcp://127.0.0.1:3306","root","YOURPASSWORD");

  return 0;
}
1. Install mysqlcppconn : sudo apt-get install  libmysqlcppconn-dev
2. Install mysqlclient  : sudo apt-get install libmysqlclient-dev libmysqlclient18
3. Compile it in terminal using :
   sudo g++ -Wall -I/usr/include/cppconn -o testapp tester.cpp -L/usr/lib -lmysqlcppconn -lmysqlclient

Thank's to Mike and Biffen.

Community
  • 1
  • 1
Rizky
  • 414
  • 6
  • 20
  • It looks like you're not linking with some MySQL library. What's the linker command? – Biffen Dec 05 '14 at 07:32
  • I compile the code in terminal using : sudo g++ -Wall -I/usr/include/cppconn -o testapp tester.cpp -L/usr/lib -lmysqlcppconn – Rizky Dec 05 '14 at 07:36
  • Could it be that there's some other MySQL library (besides `mysqlcppconn`) that should be linked? – Biffen Dec 05 '14 at 07:45
  • I don't think so. If you see the question I linked in my question, it seems everybody's doing alright with the solution. – Rizky Dec 05 '14 at 07:49
  • usually connector/c++ is already statically linked to libmysql, that's the default setting when building the source – mukunda Dec 05 '14 at 07:57

1 Answers1

2

libmysqlcppconn is only the C++ wrapper for libmysqlclient. You need to link them both in order for it to work (along with any other dependencies).

Mike
  • 2,721
  • 1
  • 15
  • 20
  • I think I've already linked it, I compile it using : sudo g++ -Wall -I/usr/include/cppconn -o testapp tester.cpp -L/usr/lib -lmysqlcppconn – Rizky Dec 05 '14 at 07:55
  • @rizkynggakool Which part of that command would you say links `libmysqlclient`? – Biffen Dec 05 '14 at 07:56
  • oh my bad, I haven't link the libmysqlclient, but I can't get libmysqlclient, I try sudo apt-get install libmysqlclient but package not found – Rizky Dec 05 '14 at 08:01
  • 1
    sudo apt-get install libmysqlclient-dev libmysqlclient18. You will also need mysql-common but it will probably install that automatically. If not, browse the repository using Synaptic package manager. – Mike Dec 05 '14 at 08:12
  • @Mike I've installed the libmysqlclient-dev and then recompile it using : sudo g++ -Wall -I/usr/include/cppconn -o testapp tester.cpp -lmysqlclient but the result is still like the edit that I made in the question – Rizky Dec 05 '14 at 08:37
  • @rizkynggakool You probably need *both* `-lmysqlclient` and `-lmysqlcppconn`. – Biffen Dec 05 '14 at 08:51
  • @Biffen oh my... it is working... thank you very much.. I'll edit this question – Rizky Dec 05 '14 at 08:55