C++ mysql 仅在构建解决方案时LNK2019错误

C++ mysql LNK2019 errors only while building solution

本文关键字:LNK2019 错误 解决方案 构建 mysql C++      更新时间:2023-10-16
Error   LNK1120 6 unresolved externals      
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall sql::SQLString::~SQLString(void)" (__imp_??1SQLString@sql@@QAE@XZ) referenced in function _main    
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall sql::SQLString::SQLString(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0SQLString@sql@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main      
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall sql::SQLString::SQLString(char const * const)" (__imp_??0SQLString@sql@@QAE@QBD@Z) referenced in function _main        
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall sql::SQLString::operator class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &(void)const " (__imp_??BSQLString@sql@@QBEABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function _main     
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const & __thiscall sql::SQLString::asStdString(void)const " (__imp_?asStdString@SQLString@sql@@QBEABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function "bool __cdecl sql::operator!=(class sql::SQLString const &,class sql::SQLString const &)" (??9sql@@YA_NABVSQLString@0@0@Z)   
Error   LNK2019 unresolved external symbol __imp__get_driver_instance referenced in function _main

这仅在构建项目未编译时发生

我已经四处寻找解决方案,只是找不到一个尝试过不同库的库,都出现了这个问题

#include "driver/mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
int main()
{
string Username;
string Pass;
try {
    sql::ResultSet *res;
    sql::ResultSet *res2;
    sql::Driver *driver;
    sql::Connection *con;
    sql::Statement *stmt;   

    bool loggingin = true;
    driver = get_driver_instance();
//place holder text not actualy there       
con = driver->connect("[host]", "[username]", "[password]");
    con->setSchema("Information");
    stmt = con->createStatement();
    res = stmt->executeQuery("Get Password where Username = '" + Username + "'");
    res2 = stmt->executeQuery("Get HWID where Username = '" + Username + "'");
    while (loggingin) {
        printf("Please Type Your Username: n >>");
        cin >> Username;
        printf("Please Type Your Password: n >>");
        cin >> Pass;


        res = stmt->executeQuery("Get Password where Username = '" + Username + "'");
        string password = res->getString(1);
        ;
        while (res->next()) {
            if (res->getRow() == 0 || password != Pass) {
                printf("Username or Password Wrong");
            }
            else {
                if (res2->getString(1) != getHWID()) {
                    exit(1);
                }
                else {
                    loggingin = false;

                }
            }
            break;
        }

    }
    delete con;
    delete res;
    delete res2;
    delete stmt;
}
catch (sql::SQLException &e) {
    system("cls");
    printf("please reload");
    while (true) {
        Sleep(1);
    }
}

我只是想让它构建,没有其他问题,只是它无法构建

通过将mysqlcppconn.lib和mysqlcppconn-static.lib添加到Linker>Input>extra Dependancy来修复