MySQL C ++连接器

时间:2014-12-05 07:21:00

标签: c++ mysql


我正在使用MySQL / C ++ Connector 我在d3l中尝试了“question”提供的解决方案 然后我得到了这个错误:

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

我正在运行Ubuntu 14 请帮忙。

编辑:
正如'mukunda'所说:
“通常连接器/ c ++已经静态链接到libmysql,这是构建源代码时的默认设置”

所以我用:

编译它
  

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

然后将错误减少到:

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

再次编辑:
这是构建此代码的必要步骤:

#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

感谢Mike和Biffen。

1 个答案:

答案 0 :(得分:1)

libmysqlcppconn只是libmysqlclient的C ++包装器。您需要将它们链接起来以使其工作(以及任何其他依赖项)。