vc++2013中使用MySQL connector/C++ 1.1.4静态链接报错
包含头文件
#include <mysql_connection.h>
#include <mysql_driver.h>
#include <cppconn/statement.h>
#include <cppconn/resultset.h>
#include <cppconn/exception.h> #ifdef _DEBUG
#pragma comment(lib, "mysqlcppconn.lib")
#else
#pragma comment(lib, "mysqlcppconn-static.lib")
// 我的MySQL connector/C++是自己下源码编译的,需要引入这个,官方直接提供的二进制我不清楚需要不需要
#pragma comment(lib, "mysqlclient.lib")
#endif
代码
try
{
const char* user = "root";
const char* passwd = "";
const char* host = "tcp://192.168.1.8:3306";
const char* database = "mysql"; sql::mysql::MySQL_Driver* driver = sql::mysql::get_driver_instance();
sql::Connection* conn = driver->connect(host, user, passwd);
conn->setSchema(database); sql::Statement *stmt = conn->createStatement(); sql::ResultSet *res = stmt->executeQuery("select * from user;");
while (res->next()) {
AfxMessageBox((res->getString() + " | " + res->getString()).c_str());
} delete res;
delete stmt;
delete conn; }
catch (sql::SQLException e) {
CString strErrorMsg;
strErrorMsg.Format("MySQL error code %d: %s, %s", e.getErrorCode(), e.what(), e.getSQLState().c_str());
AfxMessageBox(strErrorMsg);
if (e.getErrorCode() == ) {
AfxMessageBox("");
}
}
catch (std::runtime_error e) {
AfxMessageBox(e.what());
}
静态链接
>TestDlg.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) class sql::mysql::MySQL_Driver * __cdecl sql::mysql::get_driver_instance(void)" (__imp_?get_driver_instance@mysql@sql@@YAPAVMySQL_Driver@@XZ)
>TestDlg.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: virtual __thiscall sql::SQLException::~SQLException(void)" (__imp_??1SQLException@sql@@UAE@XZ)
>TestDlg.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: int __thiscall sql::SQLException::getErrorCode(void)const " (__imp_?getErrorCode@SQLException@sql@@QBEHXZ)
>TestDlg.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const & __thiscall sql::SQLException::getSQLState(void)const " (__imp_?getSQLState@SQLException@sql@@QBEABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@@@std@@XZ)
>TestDlg.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: char const * __thiscall sql::SQLString::c_str(void)const " (__imp_?c_str@SQLString@sql@@QBEPBDXZ)
>TestDlg.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall sql::SQLString::SQLString(char const * const)" (__imp_??0SQLString@sql@@QAE@QBD@Z)
>TestDlg.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall sql::SQLString::~SQLString(void)" (__imp_??1SQLString@sql@@QAE@XZ)
通过观察cppconn/build_config.h得知若要得到非__declspec(dllimport)方式的引入需要定义宏CPPCONN_LIB_BUILD
解决方案
在包含头文件前定义宏CPPCONN_LIB_BUILD,告诉链接器MySQL connector是静态库方式编译的即可
#ifndef _DEBUG
#define CPPCONN_LIB_BUILD
#endif #include <mysql_connection.h>
#include <mysql_driver.h>
#include <cppconn/statement.h>
#include <cppconn/resultset.h>
#include <cppconn/exception.h>
#ifdef _DEBUG
#pragma comment(lib, "mysqlcppconn.lib")
#else
#pragma comment(lib, "mysqlcppconn-static.lib")
// 我的MySQL connector/C++是自己下源码编译的,需要引入这个,官方直接提供的二进制我不清楚需要不需要
#pragma comment(lib, "mysqlclient.lib")
#endif
vc++2013中使用MySQL connector/C++ 1.1.4静态链接报错的更多相关文章
- win10 安装mysql 8.0.18 解决Navicat初次连接报错
win10 安装mysql 8.0.18 解决Navicat初次连接报错 win10 安装mysql 8.0.18-winx64 一,先去官网下载mysql 安装包 https://dev.mysql ...
- 在Visual Studio 2013中安装Mysql for EntityFramework
1. 安装Visual Studio 20132. 下载mysql,安装mysql.3. 下载 mysql-for-visualstudio-1.2.7.msi, 下载链接:https://cdn.m ...
- VC编程中如何设置对话框的背景颜色和静态文本颜色
晚上编一个小程序,涉及到如何设置对话框的背景颜色和静态文本颜色.这在VC6.0中本来是一句话就搞定的事.在应用程序类中的InitInstance()函数添加: //设置对话框背景和文本颜色 SetDi ...
- 在CentOS里使用MySQL Connector/C++
操作系统版本:CentOS6 64位 1,安装boost库.因为MySQL Connector/C++使用了boost库,所以必须先安装boost库,我们才能使用MySQL Connector/C++ ...
- python操作mysql——mysql.connector
连接mysql, 需要mysql connector, conntector是一种驱动程序,python连接mysql的驱动程序,mysql官方给出的名称为connector/python, 可参考m ...
- Python:安装MYSQL Connector
在Python中安装MySQL Connector有如下三种方法: 1.直接安装客户端[建议使用] pip install mysqlclient 2.安装mysql连接器 pip install - ...
- 安装MySQL Connector/C++并将其配置到VS2015中
安装MySQL Connector/C++并将其配置到VS中 1.下载MySQL Connector/C++并安装 在下载地址:https://dev.mysql.com/downloads/conn ...
- [转]MySQL Connector/C++(一)
http://www.cnblogs.com/dvwei/archive/2013/04/18/3029464.html#undefined#undefined MySQL Connector/C++ ...
- Windows server 2008 R2中安装MySQL !
我今天打算在Windows server 2008 R2中安装MySQL,可是总是发现ODBC连接器安装错误,无论我采用MySQL的整体安装包,还是单独的ODBC连接器安装文件!! 最后上网搜索了很久 ...
随机推荐
- 推荐15款制作 SVG 动画的 JavaScript 库
在当今时代,SVG是最流行的和正在被众多的设计人员和开发人员使用,创建支持视网膜和响应式的网页设计.绘制SVG不是一个艰巨的任务,因为大量的 JavaScript 库可与 SVG 图像搭配使用.这些J ...
- iframe高度自适应
前两天在网上看到了一道面试题,问iframe高度自适应的问题.发现自己之前几乎没有关注过iframe的问题,所以在这里记录一下. 原题目是: 页面A的域名是:http://www.taobao.com ...
- JavaScript的几种Math函数,random(),ceil(),round(),floor()
1.Math.random():返回 0 ~ 1 之间的随机数.2.Math.ceil():返回值:返回大于或等于x,并且与之最接近的整数(如果x是正数,则把小数"入":如果x是负 ...
- Mysql(Mariadb) 基础操作语句 (持续更新)
基础SQL语句,记录以备查阅.(在HeiDiSql中执行) # 创建数据库 Create Database If Not Exists VerifyIdear Character Set UTF8; ...
- arcgis server之路网服务发布
路网服务发布首先需要建立好道路的网络集,为了保证道路网络分析的准确性,建立网络集之前,要对道路图层进行拓扑差错,确保道路的连通性.具体操作流程为:道路拓扑差错-建立几何网络集-路网服务发布. 1.道路 ...
- Sharepoint学习笔记—习题系列--70-573习题解析 -(Q142-Q143)
Question 142You have a Feature that contains an image named ImageV1.png.You plan to create a new ver ...
- Jquery——简单的视差滚动效果,兼容PC移动端
$(function(){ $(window).scroll(function(){ var top=$(this).scrollTop(); $(". ...
- iOS __block 与 __weak
关于__block 与__weak http://stackoverflow.com/questions/19227982/using-block-and-weak 一下是一些区别的介绍 MRC: _ ...
- weblogic安装注意事项_linux
➠更多技术干货请戳:听云博客 一.安装过程:参考“weblogic安装截屏(linux)” 注意事项:安装weblogic时,需要注意以下两点: 1.首先在安装目录下创建weblogic12文件夹 如 ...
- ImageView学习
package liu.roundimagedemo.view; import android.content.Context; import android.graphics.Bitmap; imp ...