0

Okay, so I got my code from here:

#include <iostream>
#include <mysql.h>

MYSQL* connection, mysql;
MYSQL_RES* result;
MYSQL_ROW row;
int query_state;

using std::string;
using std::cout;
using std::cin;
using std::endl;

int main()
{
    mysql_init(&mysql);

    string password;
    cout << "Input Password: "; cin >> password; cout << endl;
    connection = mysql_real_connect(&mysql, "localhost", "osamakawish", password.c_str(),"Cpp",0,0,0);

    if (connection == NULL) cout << mysql_error(&mysql) << endl;

    mysql_free_result(result);
    mysql_close(connection);

    return 0;
}

And I'm receiving the following errors:

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol _mysql_error@4 referenced in function _main  Cpp C:\Users\osama\source\repos\Cpp\Cpp.obj 1   

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol _mysql_init@4 referenced in function _main   Cpp C:\Users\osama\source\repos\Cpp\Cpp.obj 1   

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol _mysql_real_connect@32 referenced in function _main  Cpp C:\Users\osama\source\repos\Cpp\Cpp.obj 1   

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol _mysql_free_result@4 referenced in function _main    Cpp C:\Users\osama\source\repos\Cpp\Cpp.obj 1   

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol _mysql_close@4 referenced in function _main  Cpp C:\Users\osama\source\repos\Cpp\Cpp.obj 1   

Severity    Code    Description Project File    Line    Suppression State
Error   LNK1120 5 unresolved externals  Cpp C:\Users\osama\source\repos\Cpp\Debug\Cpp.exe   1   

So I found this on StackOverflow, and realized this is an issue of function definition vs declaration.

Under Project > Cpp Properties > Configuration Properties > C/C++, I have:

Additional Include Directions > C:\Program Files\MySQL\MySQL Server 8.0\include;%(AdditionalIncludeDirectories)

So I checked the include folder in the MySQL Server 8.0 directory, and I found the mysql.h file but no mysql.c file, and the above mysql_ functions were declared but not defined in the mysql.h file.

I am assuming this is the source of the issue. However, I'm not sure where the definitions for those functions are supposed to be.

Either that or I have the wrong idea for the source of the issue.

So basically this is what I've done so far, and have come here since I'm not sure what to do next to resolve this issue. Any help would be welcome, to be honest, as connecting sql to code has always been proving to be exhausting for one reason or another.

Osama Kawish
  • 312
  • 1
  • 5
  • 15
  • I think you are missing a library that you need to add to the linker->Input->Additional Dependencies. – drescherjm Jun 06 '20 at 00:50
  • I really hate it when StackOverflow closes questions so quickly, it gets annoying. The redirected link is completely generic and offers a long list of possible solutions and reasons for the issue. Why exactly is it bad to ask something a little more specific to my case, instead of reading through several links of issues just to arrive at my own? – Osama Kawish Jun 06 '20 at 01:21

0 Answers0