I am trying to connect to a sql database using ODBC in c++ and I can't call any of the functions in sql.h file: Here is my test code:
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(){
SQLHANDLE SQLEnvHandle;
SQLRETURN myRet = SQLAllocStmt(NULL,NULL);
cout<<cos(3.0);
return 0;
}
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe générer le fichier actif",
"command": "C:\\Users\\caronfe\\AppData\\Local\\msys2\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compilateur : C:\\Users\\caronfe\\AppData\\Local\\msys2\\mingw64\\bin\\g++.exe"
}
]
}
I tried to compile with g++, getting this error:
undefined reference to `SQLAllocStmt'
When I switch one of the NULL parameters to an integer, the compiler gives me this error instead:
invalid conversion from 'int' to 'SQLHDBC'
So the compiler find the function, but still throws an undefined reference error. The same behavior happens for other sql.h functions, but not for any other import. Config: I am on windows 10 and mingw64 is installed for the user only I am using VSCode editor (Intellisense also finds the functions...) Other codes not using sql.h compiles and execute perfectly Compiler: g++ (Rev1, Built by MSYS2 project) 11.3.0