我尝试在Visual Studio代码中将我的C++代码与MariaDB服务器(在本地主机上运行)连接
但是,当我编写#include <mariadb/conncpp.hpp>
时,Intellisense发现了错误。
错误:
#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit
cannot open source file "mariadb/conncpp.hpp"
"我已经做过的事"
1.使用MSYS2安装Clang compiler with debugger (toolchain package)
1.从official website.安装MariaDB社区服务器
1.从official website.安装MariaDB连接器/C++
1.按照MariaDB Connector/C++文档进行安装(* 包括将PATH添加到系统环境变量 *)
1.通过在Visual Studio代码c_cpp_properties.json
文件中添加C:\Program Files\MariaDB\MariaDB C++ Connector 64-bit
来包括PATH。
1.重新启动Visual Studio程式码。
代码:
#include <iostream>
#include <mariadb/conncpp.hpp>
using namespace std;
int main() {
// Instantiate Driver
sql::Driver* driver = sql::mariadb::get_driver_instance();
// Configure Connection
sql::SQLString url("jdbc:mariadb://localhost:3306/todo");
sql::Properties properties({{"user", "app_user"}, {"password", "Password123!"}});
// Establish Connection
std::unique_ptr<sql::Connection> conn(driver->connect(url, properties));
cout << "Hello World!" << endl;
}
1条答案
按热度按时间ohtdti5x1#
根据5.你的包含路径是
C:\Program Files\MariaDB\MariaDB C++ Connector 64-bit
。这是不对的:默认情况下,MariaDB连接器将包含文件安装在
[installdir]/include
中,因此您的包含路径应为C:\Program Files\MariaDB\MariaDB C++ Connector 64-bit\include
。