include <mysql/mysql.h> error"undefined reference to"

Sysprogs forums Forums VisualGDB include <mysql/mysql.h> error"undefined reference to"

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #898
    Anonymous
    Participant

    Hello,

    I am try something with Visual Studio 2012 and Visual GDB on my Raspberry to get his kind of code example running but without success.
    I downloaded on the raspery the mysql Libs and do a sync sysroot on Visual GDB.

    #include
    #include

    using namespace std;
    #define SERVER “localhost”
    #define USER “root”
    #define PASSWORD “manager”
    #define DATABASE “Lagerverwaltung”

    int main()
    {
    MYSQL *connect;
    connect=mysql_init(NULL);
    if (!connect)
    {
    cout<<"MySQL Initialization failed";
    return 1;
    }
    connect=mysql_real_connect(connect, SERVER, USER, PASSWORD , DATABASE ,0,NULL,0);
    if (connect)
    {
    cout<<"connection Succeededn";
    }
    else
    {
    cout<<"connection failedn";
    }
    MYSQL_RES *res_set;
    MYSQL_ROW row;
    mysql_query (connect,”select * from example;”);
    unsigned int i =0;
    res_set = mysql_store_result(connect);
    unsigned int numrows = mysql_num_rows(res_set);
    while (((row= mysql_fetch_row(res_set)) !=NULL ))
    { //cout<<" %sn",row !=NULL?row : “NULL”;

    cout <<"t | t" << row << "t | t";
    cout << row[i+1] << "t |"<< endl;
    }
    mysql_close (connect);
    return 0;
    }

    If i try to compile it I get this kind of errors
    C:UsersDieterDropboxRepositoryWorkspace_WindowsSoftwareDB_SicherungDB_BackUpDB_BackUp/DB_BackUp.cpp:13: undefined reference to `mysql_init’
    C:UsersDieterDropboxRepositoryWorkspace_WindowsSoftwareDB_SicherungDB_BackUpDB_BackUp/DB_BackUp.cpp:19: undefined reference to `mysql_real_connect’
    C:UsersDieterDropboxRepositoryWorkspace_WindowsSoftwareDB_SicherungDB_BackUpDB_BackUp/DB_BackUp.cpp:30: undefined reference to `mysql_query’
    C:UsersDieterDropboxRepositoryWorkspace_WindowsSoftwareDB_SicherungDB_BackUpDB_BackUp/DB_BackUp.cpp:32: undefined reference to `mysql_store_result’
    C:UsersDieterDropboxRepositoryWorkspace_WindowsSoftwareDB_SicherungDB_BackUpDB_BackUp/DB_BackUp.cpp:33: undefined reference to `mysql_num_rows’
    C:UsersDieterDropboxRepositoryWorkspace_WindowsSoftwareDB_SicherungDB_BackUpDB_BackUp/DB_BackUp.cpp:34: undefined reference to `mysql_fetch_row’
    C:UsersDieterDropboxRepositoryWorkspace_WindowsSoftwareDB_SicherungDB_BackUpDB_BackUp/DB_BackUp.cpp:40: undefined reference to `mysql_close’

    Which settings must be changed during compilation?

    Br
    Dieter

    #3364
    support
    Keymaster

    Hi,

    You need to add the MySQL library to the ‘libraries’ setting in the VisualGDB Project Properties. Specify the name without the ‘lib’ prefix and ‘.a’ suffix. E.g. if the library name is libmysql.a, simply specify ‘mysql’ in the ‘libraries’ field.
    You may also need to put extern “C” around the include file if it does not contain it.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.