I'm trying to do a simple mysql connection with C++, I am using VSCode and g++ for compiling.
The error is
/tmp/cc79SKd5.o: In function `main':
/home/cameron/Documents/CodingTutorials/DBtest/main.cpp:5: undefined reference to `mysql_init'
/home/cameron/Documents/CodingTutorials/DBtest/main.cpp:6: undefined reference to `mysql_real_connect'
Searching around previous posts it seems like I haven't included the correct linking arguments, I found this post Mysql with C++ error: undefined reference to mysql_init but I don't understand how to do this in VScode.
I think I'm missing something basic here.
My code is
#include<iostream>
#include<mysql/mysql.h>
int main(){
MYSQL* conn;
conn = mysql_init(0);
conn = mysql_real_connect(conn,"192.168.0.112","root","xxx","testDB",0,NULL,0);
if (conn){
std::cout<<"DB Connected";
}
};
My Launch.json is
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/main",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
My c_cpp_properties is
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/mysql/**",
"/usr/include/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"compilerArgs":["mysql_config --cflags --libs"],
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}