MySQL数据库连接到一个c++win32项目
MySQL database connection to a c++ win32 project
我正在尝试将MySQL数据库连接到我的学校c++Win32项目。我已经建立了visual studio,所有的包括文件和目录,正如我的教授告诉我的,这是她在安装MySQL和连接器后告诉我的:
- Windows Visual Studio
1) 如果您使用Microsoft Visual Studio作为您的c++编辑器。a.转到解决方案资源管理器,右键单击项目,然后找到项目属性。在"配置属性"中,找到C/C++并单击"常规",然后在通过键入这三个头文件的目录库,例如MySQL Server 5.5的include目录包括MySQL连接器C++1.1.3的目录,以及Boost 1.55.0。b.在项目属性图的树状视图中,打开Linker,一般,附加图书馆目录。添加${MySQL}/lib/opt目录添加到"其他库目录"文本字段中,然后添加${MySQL_Connector}/lib目录目录文本字段。
在那之后,我进行了编译,一切都很好,然后我添加了用于建立连接的代码,该代码位于按钮单击的事件处理程序中。我的#include语句如下:
#include "stdafx.h"
#include "AddBook.h"
#include "afxdialogex.h"
#include "resource.h"
#include <windows.system.h>
#include <mysql.h>
#include <mysql_connection.h>
#include <mysql_driver.h>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
using namespace std;
using namespace sql;
using namespace sql::mysql;
因此,她的连接示例是这样的(包括上面的所有包含文件):
int main(void)
{
//cout << endl;
//cout << "Running 'SELECT 'Hello World!' » AS _message'..." << endl;
try
{
sql::Driver *driver;
sql::Connection *con;
/**
* To establish a connection to MySQL Server,
* retrieve an instance of sql::Connection from a sql::mysql::MySQL_Driver obj
*/
driver = get_mysql_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "mysql");
/* Example 1: create table and insert records */
{
cout << "To build a connection..." << endl;
con = driver->connect("tcp://127.0.0.1:3306", "root", "mysql");
sql::Statement *stmt;
sql::ResultSet *res;
stmt = con->createStatement();
cout << "To create a table..." << endl;
stmt->execute("USE cop2335");
stmt->execute("DROP TABLE IF EXISTS test");
stmt->execute("CREATE TABLE test(id INT, label CHAR(1))");
stmt->execute("INSERT INTO test(id, label) VALUES (1, 'a')");
con->close();
}
但没有奏效。它给了我错误:
错误LNK2019:未解析的外部符号"__declspec(dllimport)public:_thiscall sql::SQLString::~SQLString(void)"(_imp_??1SQLString@sql@@QAE@XZ)
错误LNK2019:未解析的外部符号"__declspec(dllimport)public:__thiscall sql::SQLString::SQLString(char const*const)"(_imp??0SQLString@sql@@QAE@QBD@Z)
错误LNK2019:未解析的外部符号"__declspec(dllimport)class sql::mysql::mysql_Driver*__cdecl sql::mysql::get_Driver_instance(void)"(_imp?get_driver_instance@mysql@sql@@YAPAVMySQL_Driver@12@XZ)在函数"class sql::mysql::mysql_Driver*__cdecl sql::mysql::get_mysql_Driver_instance(void)"(?get_mysql_driver_instance@mysql@sql@@YAPAVMySQL_Driver@12@XZ)
这是我的代码(即给出上述错误的代码)(注释//2下没有两行。。。代码编译完美,没有任何问题):
void AddBook::OnBnClickedenterbtnaddbook()
{
sql::mysql::MySQL_Driver *driver;
sql::Connection *con;
//1. get text from dialog textedit box
//2. initialize a DB connection
driver = sql::mysql::get_mysql_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "password");
// 3. update DB
}
我也这样尝试过:http://www.nitecon.com/tutorials-articles/develop/cpp/c-mysql-beginner-tutorial/
但它给了我同样的错误"Link2019"
这里有我失踪的东西吗?是否有其他方法将数据库连接到项目?欢迎所有帮助。也谢谢你的阅读。
未解析的外部符号通常意味着某个函数有声明,但没有定义。
例如
Foo.h
class A {
void foo1();
void foo2();
}
Foo.cpp
void A::foo2() {
}
顺便说一句,在您的情况下,不包括包含定义的lib.dll文件的接缝。
- C++线程:如何在一个线程仍在运行时阻止另一个线程执行 (Win32)
- 一个非常简单的win32套接字代码,但工作错误
- 如果我有五个 Win32 静态控件,如何使用特定的前景色设置其中一个?
- win32 c++ 我想在静态标签的文本之后直接插入一个 EDIT 控件
- 一个简单的 win32 多线程代码.这能行吗?
- 我有一个AA树C 实现源代码,我需要将该代码放入Win32 C 中
- Win32/Gdigrab - 如何将另一个进程窗口设置为无边框
- Win32打开一个文件夹
- 如何制作一个不依赖msvc dll的win32应用程序
- 在Win32管道上将两个缓冲区合并为一个写操作
- 使用 Win32 中的 HBITMAP 绘制一个二维数组,C++
- 如何使用C Win32 API在登录对话框中显示最后一个登录用户名
- 我的Visual C++Win32中有一个无法关闭的MessageBox!发生了什么
- 哪一个是针对Win32和Win64开发的最低Visual Studio版本
- 从 Win32 包装器 WndProc 调用另一个类中的函数
- MySQL数据库连接到一个c++win32项目
- 在 Win32 (c++) 中的另一个进程中写入文本框
- C++/Win32 如何每秒加载一个函数
- 等待另一个进程锁定然后解锁 Win32 互斥锁
- 从头开始创建一个c++ win32程序