“对_imp__get_driver_instruction的未定义引用”错误不断出现

时间:2018-01-08 15:57:50

标签: c++ mysql boost cmake

我目前正在使用安装了boost的MySQL Connector。我设法处理除了这个之外的所有其他错误。每次我尝试在CLion中构建我的项目时,我都会收到一条错误消息:“对_imp__get_driver_instance的未定义引用”。

这是我的Cmake文件:

cmake_minimum_required(VERSION 3.8)
project(Learn_Cpp)


set(CMAKE_CXX_STANDARD 17)

include_directories("C:/mysql-connector-c++-noinstall-1.1.9-win32/include" "C:/mysql-connector-c++-noinstall-1.1.9-win32/include/cppconn" "C:/boost_1_66_0")

set(SOURCE_FILES "C++ Tutorials/ClassFile.cpp" "C++ Tutorials/ClassFile.h" "C++ Tutorials/Learn.cpp")
add_executable(Learn_Cpp ${SOURCE_FILES})

这是我从此website复制的代码:

#include <iostream>
#include <stdlib.h>


#include "mysql_connection.h"
#include "mysql_driver.h"
#include <cppconn/exception.h>

#include <cppconn/resultset.h>
#include <cppconn/statement.h>


using namespace std;


int main() {
    cout << endl;
    cout << "Running 'SELECT 'name' AS nameAKA'..." << endl;

    try {
        sql::Driver *driver;
        sql::Connection *con;
        sql::Statement *stmt;
        sql::ResultSet *res;

        /*Create a Connection*/
        driver = get_driver_instance();
        con = driver->connect("localhost", "root", "");
        /*Set schema*/
        con->setSchema("stickyricetest");

        stmt = con->createStatement();
        res = stmt->executeQuery("SELECT 'name' AS nameAKA");
        while(res->next()) {
            cout << "\t... MySQL Replies";
            /* Access column data by alias or column name*/
            cout << res->getString("nameAKA") << endl;
            cout << "\t... MySQL says it again";
            /* Access column data by numeric offset, 1 is the first column*/
            cout << res->getString(1) << endl;
        }
        delete res;
        delete stmt;
        delete con;

    } catch (sql::SQLException &e){
        cout << "# ERR: SQLException in" << __FILE__;
        cout << "(" << __FUNCTION__ << ") on line" << __LINE__ << endl;
        cout << "# ERR: " << e.what();
        cout << " (MySQL error code: " << e.getErrorCode();
        cout << ", SQLState: " << e.getSQLState() << ")" << endl;
    }

    cout << endl;

    return EXIT_SUCCESS;

};

最后这是我收到的错误消息:

"C:\Program Files\JetBrains\CLion 2017.2.3\bin\cmake\bin\cmake.exe" --build C:\Users\Timothy\CLionProjects\Learn_Cpp\cmake-build-debug --target Learn_Cpp -- -j 4
Scanning dependencies of target Learn_Cpp
[ 33%] Building CXX object CMakeFiles/Learn_Cpp.dir/C++_Tutorials/Learn.cpp.obj
[ 66%] Linking CXX executable Learn_Cpp.exe
CMakeFiles\Learn_Cpp.dir/objects.a(Learn.cpp.obj): In function `main':
C:/Users/Timothy/CLionProjects/Learn_Cpp/C++ Tutorials/Learn.cpp:31: undefined reference to `_imp__get_driver_instance'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\Learn_Cpp.dir\build.make:123: recipe for target 'Learn_Cpp.exe' failed
mingw32-make.exe[3]: *** [Learn_Cpp.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/Learn_Cpp.dir/all] Error 2
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Learn_Cpp.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/Learn_Cpp.dir/rule] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Learn_Cpp.dir/rule' failed
Makefile:117: recipe for target 'Learn_Cpp' failed
mingw32-make.exe: *** [Learn_Cpp] Error 2

我该怎么做才能解决这个问题?我在过去几个小时内遇到过这种情况,但在其他论坛或手册中找不到解决方案。

任何帮助都将不胜感激。

0 个答案:

没有答案