I know it’s a very old problem, but this time, in my opinion, it’s a vscode configuration problem
This is the affected piece of code and the error is what you see in the post header.
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
using namespace std;
int main(void)
{
cout << endl;
cout << "Let's have MySQL count from 10 to 1..." << endl;
try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
sql::PreparedStatement *pstmt;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
/* Connect to the MySQL test database */
con->setSchema("test");
Running or debugging I get the infamous error.
Why do I say it’s a C++ config problem in vscode? Because if I run this command from the terminal everything works correctly and the executable is created.
g++ -o readdb readdb.cpp -L/usr/lib/ -lmysqlcppconn -lmysqlclient
This is settings.json
{
"git.openRepositoryInParentFolders": "never",
"workbench.startupEditor": "none",
"editor.minimap.enabled": false,
"sqltools.connections": [
],
"terminal.integrated.fontFamily": "monospace",
"editor.inlineSuggest.suppressSuggestions": true,
"editor.snippetSuggestions": "top",
"editor.suggest.snippetsPreventQuickSuggestions": true,
"python.createEnvironment.trigger": "off",
"terminal.integrated.fontSize": 14,
"terminal.integrated.persistentSessionReviveProcess": "never",
"breadcrumbs.enabled": false,
"editor.stickyScroll.enabled": false,
"debug.terminal.clearBeforeReusing": true,
"security.workspace.trust.untrustedFiles": "open",
"dart.flutterSdkPath": "/root/flutter",
"workbench.colorTheme": "Darcula",
"cmake.configureOnOpen": true,
"C_Cpp.default.compilerArgs": [
"-L/usr/lib/ -lmysqlcppconn -lmysqlclient"
],
}
and this is c_cpp_properties.json
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/cppconn"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"compilerArgs": [ "-lmysqlcppconn, -lmysqlclient"],
"cStandard": "c17",
"cppStandard": "c++14",
"intelliSenseMode": "linux-clang-x64"
}
],
"version": 4
}