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连接器安装文件!! 最后上网搜索了很久 ...
随机推荐
- 利用CSS3D效果制作简易旋转木马效果
最近看一下css3d的一些特性,想着也实验学习一下,制作个小demo之类的.就练习了一下.开发一个粗糙的选择木马效果,如图 其实就是找到角度和位置,计算每根柱子的旋转角度摆放到3d空间的置顶位置即可. ...
- css相对定位和绝对定位
相对定位,是对原来元素的位置为参照物进行定位: 绝对定位,如果父级没有定位,则针对HTML为参照物进行定位:如果父级有定位,则针对父元素为参照物进行定位
- 关于SharePoint 2013的工作流(二)
摸索完了如何画流程实现功能接下来,就是如何配置和部署了.在添加工作流之前,肯定需要一个审批人的配置以及阀值等等的配置. 这个的实现基本上和以前的工作流一致.写法却不一样了,模板自带的都是用js实现的. ...
- Gradle's dependency cache may be corrupt解决方法
问题描述: Error:Unable to find method 'com.google.common.cache.CacheBuilder.build(Lcom/google/common/cac ...
- ThinkPHP3快速入门教程-:基础
一.ThinkPHP的认识: ThinkPHP是一个快速.简单的基于MVC和面向对象的轻量级PHP开发框架. 二.下载后的目录结构: ├─ThinkPHP.php 框架入口文件 ├─Commo ...
- MySQL学习笔记之数据类型
数据类型在所有的数据库使用当中,都是避免不了的部分.以前每次写SQL语句,对于定义成哪种数据类型总是迷迷糊糊,今天就来彻底弄清.以下介绍仅针对MySQL 5.5以上版本. 一.字符串类型 1.char ...
- Oracle shutdown immediate无法关闭数据库解决方法
在测试服务器上使用shutdown immediate命令关闭数据库时,长时间无法关闭数据库,如下所示 1: [oracle@DB-Server admin]$ sqlplus / as sysdba ...
- winform窗体(五)——布局方式
一.默认布局 ★可以加panel,也可以不加: ★通过鼠标拖动控件的方式,根据自己的想法布局.拖动控件的过程中,会有对齐的线,方便操作: ★也可选中要布局的控件,在工具栏中有对齐工具可供选择,也有调整 ...
- SQL Server 2008 R2——查找最小nIndex,nIndex存在而nIndex+1不存在 求最小连续数组中的最大值
=================================版权声明================================= 版权声明:原创文章 谢绝转载 请通过右侧公告中的“联系邮 ...
- 005.nginx配置文件
1.替换nginx主配置文件 通过前面的配置,LNMP的环境已经搭建完成,现在我们替换nginx配置文件: [root@huh ~]# cd /usr/local/nginx/conf/[root@h ...