簡體   English   中英

MySQL C ++連接器

[英]MySQL C++ Connector


我正在使用MySQL / C ++ Connector。
我在這個問題上嘗試了d3l提供的解決方案
然后我得到了這個錯誤:

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。
請幫忙。

編輯:
正如穆昆達所說:
“通常connector / c ++已經靜態鏈接到libmysql,這是構建源代碼時的默認設置”

所以我用:

須藤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

謝謝邁克和比芬。

libmysqlcppconn只是libmysqlclient的C ++包裝器。 您需要將它們鏈接在一起,以使其正常工作(以及其他任何依賴項)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM