3

I have been trying to fetch some values from a database, so I downloaded & installed this. I included the needed headers and faced this linker errors. (I'm also using boost.)

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::SQLException::getSQLState(void)const " (__imp_?getSQLState@SQLException@sql@@QBEABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function __catch$_main$0
error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall sql::SQLException::getErrorCode(void)const " (__imp_?getErrorCode@SQLException@sql@@QBEHXZ) referenced in function __catch$_main$0
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(char const * const)" (__imp_??0SQLString@sql@@QAE@QBD@Z) referenced in function _main
error LNK2019: unresolved external symbol __imp__get_driver_instance 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 "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class sql::SQLString const &)" (??6std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@ABVSQLString@sql@@@Z)
fatal error LNK1120: 6 unresolved externals

I also got a couple of warnings like this:

warning C4251: 'sql::mysql::MySQL_Connection::proxy' : class 'boost::shared_ptr<T>' needs to have dll-interface to be used by clients of class 'sql::mysql::MySQL_Connection'

#include "stdafx.h"
#include <stdlib.h>
#include <iostream>
#include "mysql_connection.h"

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

using namespace std;

int main(void)
{
    try
    {
        sql::Driver *driver;
        sql::Connection *con;
        sql::Statement *stmt;
        sql::ResultSet *res;

        /* Create a connection */
        driver = get_driver_instance();
        con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
        /* Connect to the MySQL test database */
        con->setSchema("trinity");

        stmt = con->createStatement();
        res = stmt->executeQuery("SELECT * FROM test WHERE test='Tester'"); // replace with your statement
        while (res->next())
        {
            cout << "\t... MySQL replies: ";
            /* Access column data by alias or column name */
            cout << res->getString("_message") << endl;
            cout << "\t... MySQL says it again: ";
            /* Access column fata 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;
}

Does anyone know what may happened there ?

2 Answers 2

2

Have you also add correct library ? It seems (you write, you have added headers), that you are running Visual Studio, so either do #pragma comment(lib, <mysql lib>) or add that lib in projects settings under Linker

Sign up to request clarification or add additional context in comments.

5 Comments

So... I deleted all libraries & reinstalled MySQL connector. Now I'm facing this awesome error. FYI, this .dll file is in the SAME folder as the library. The program can't start because mysqlcppconn.dll is missing from your computer. Try reinstalling the program to fix this problem.
DLL should be in folder, from where you are running your program, or in some system dll dir. If you are running program via VS, than library is (I think), in project directory (where vcproj and other files are), not in Debug / Release
@Blacktempel Hi ,I am facing the same problem now..!! added necessary libraries in linker settings as well.. But still not working..! Could you help me.?
@ShivarajBhat Make a new question with more details and post the link to it, I can't help without more information.
I was able to fix this by including mysqlcppconn.lib in the library settings. Thanks.
0

#pragma comment(lib, "libmysql.lib")

Properties->Linker->Input->Additional-> mysqlcppconn.lib

And your project folder (Project folder name ->Debug or Release) paste the mysqlcppconn.dll

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.