Sysprogs forums › Forums › VisualGDB › include <mysql/mysql.h> error"undefined reference to"
- This topic has 1 reply, 2 voices, and was last updated 10 years, 1 month ago by support.
-
AuthorPosts
-
September 11, 2014 at 19:40 #898AnonymousParticipant
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
#includeusing 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
DieterSeptember 30, 2014 at 23:24 #3364supportKeymasterHi,
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. -
AuthorPosts
- You must be logged in to reply to this topic.