VSCode c++ mysql.h 对 'mysql_init@4' 的未定义引用
VSCode c++ mysql.h undefined reference to 'mysql_init@4'
我正在尝试让 C++ 在 VSCode 中与 mysql.h 一起工作。我已将所有文件(.h、libmysql.lib、...)放在与我的 'main.cpp' 文件相同的文件夹中,并且我尝试使用
执行程序
g++ main.cpp -I"D:\Projects\New project"
而且我不断收到以下错误:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\AppData\Local
\Temp\ccYwlVSu.o:main.cpp:(.text+0x43): undefined reference to `mysql_init@4'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\AppData\Local
\Temp\ccYwlVSu.o:main.cpp:(.text+0x8c): undefined reference to `mysql_real_connect@32'
collect2.exe: error: ld returned 1 exit status
我读到我需要 link 正确地我所有的库,我想我正在使用“-I”命令。我错过了什么?
main.cpp
#include <iostream>
#include <windows.h>
#include <mysql.h>
int main(){
MYSQL* conn;
conn = mysql_init(0);
conn = mysql_real_connect(conn, "localhost", "root", "", "airlines_db", 0, NULL, 0);
if(conn){
std::cout << "Connected" << std::endl;
} else {
std::cout << "Not connected" << std::endl;
}
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "echo",
"command": "g++",
"args": [
"-g", "main.cpp"
],
"group": {
"kind" : "build",
"isDefault": true
}
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\MinGW\bin\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x86",
"browse": {
"path": [
"C:\MinGW\lib\gcc\mingw32\9.2.0\include\c++"
]
}
}
],
"version": 4
}
我想通了 - 我的命令中缺少 -lmysql。我已经添加了,现在一切都很好!
我正在尝试让 C++ 在 VSCode 中与 mysql.h 一起工作。我已将所有文件(.h、libmysql.lib、...)放在与我的 'main.cpp' 文件相同的文件夹中,并且我尝试使用
执行程序g++ main.cpp -I"D:\Projects\New project"
而且我不断收到以下错误:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\AppData\Local
\Temp\ccYwlVSu.o:main.cpp:(.text+0x43): undefined reference to `mysql_init@4'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\AppData\Local
\Temp\ccYwlVSu.o:main.cpp:(.text+0x8c): undefined reference to `mysql_real_connect@32'
collect2.exe: error: ld returned 1 exit status
我读到我需要 link 正确地我所有的库,我想我正在使用“-I”命令。我错过了什么?
main.cpp
#include <iostream>
#include <windows.h>
#include <mysql.h>
int main(){
MYSQL* conn;
conn = mysql_init(0);
conn = mysql_real_connect(conn, "localhost", "root", "", "airlines_db", 0, NULL, 0);
if(conn){
std::cout << "Connected" << std::endl;
} else {
std::cout << "Not connected" << std::endl;
}
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "echo",
"command": "g++",
"args": [
"-g", "main.cpp"
],
"group": {
"kind" : "build",
"isDefault": true
}
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\MinGW\bin\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x86",
"browse": {
"path": [
"C:\MinGW\lib\gcc\mingw32\9.2.0\include\c++"
]
}
}
],
"version": 4
}
我想通了 - 我的命令中缺少 -lmysql。我已经添加了,现在一切都很好!