Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7063809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:45:27+00:00 2026-05-28T04:45:27+00:00

I have installed mySQL using sudo apt-get install mySQL-server then i have installed libmysqlclient15-dev

  • 0

I have installed mySQL using

sudo apt-get install mySQL-server

then i have installed libmysqlclient15-dev using

sudo apt-get install libmysqlclient15-dev

Further i have installed libmysqlc++-dev using

sudo apt-get install libmysqlc++-dev

after all this I tried to run the following code using

g++ test.c -I/usr/include/mysql -I/usr/include/mysql++

#include <mysql.h>
#include <stdio.h>
#include <stdlib.h>
#include <mysql++.h>


// just going to input the general details and not the port numbers
struct connection_details
{
    char *server;
    char *user;
    char *password;
    char *database;
};

MYSQL* mysql_connection_setup(struct connection_details mysql_details)
{
     // first of all create a mysql instance and initialize the variables within
    MYSQL *connection = mysql_init(NULL);

    // connect to the database with the details attached.
    if (!mysql_real_connect(connection,mysql_details.server, mysql_details.user, mysql_details.password, mysql_details.database, 0, NULL, 0)) {
      printf("Conection error : %s\n", mysql_error(connection));
      exit(1);
    }
    return connection;
}

MYSQL_RES* mysql_perform_query(MYSQL *connection, char *sql_query)
{
   // send the query to the database
   if (mysql_query(connection, sql_query))
   {
      printf("MySQL query error : %s\n", mysql_error(connection));
      exit(1);
   }

   return mysql_use_result(connection);
}

int main()
{
  MYSQL *conn;      // the connection
  MYSQL_RES *res;   // the results
  MYSQL_ROW row;    // the results row (line by line)

  struct connection_details mysqlD;
  mysqlD.server = "localhost";  // where the mysql database is
  mysqlD.user = "root";     // the root user of mysql   
  mysqlD.password = "123"; // the password of the root user in mysql
  mysqlD.database = "mysql";    // the databse to pick

  // connect to the mysql database
  conn = mysql_connection_setup(mysqlD);

  // assign the results return to the MYSQL_RES pointer
  res = mysql_perform_query(conn, "show tables");

  printf("MySQL Tables in mysql database:\n");
  while ((row = mysql_fetch_row(res)) !=NULL)
      printf("%s\n", row[0]);
   // clean up the database result set 
  mysql_free_result(res);
  // clean up the database link 
  mysql_close(conn);

  return 0;
}

but i got the following errors::

r@r-desktop:~/mysqlC++$ g++ test.c -I/usr/include/mysql -I/usr/include/mysql++test.c: In function ‘int main()’:
test.c:47:19: warning: deprecated conversion from string constant to ‘char*’
test.c:48:17: warning: deprecated conversion from string constant to ‘char*’
test.c:49:21: warning: deprecated conversion from string constant to ‘char*’
test.c:50:21: warning: deprecated conversion from string constant to ‘char*’
test.c:56:48: warning: deprecated conversion from string constant to ‘char*’
/tmp/ccHFL1M4.o: In function `mysql_connection_setup(connection_details)':
test.c:(.text+0xf): undefined reference to `mysql_init'
test.c:(.text+0x51): undefined reference to `mysql_real_connect'
test.c:(.text+0x65): undefined reference to `mysql_error'
/tmp/ccHFL1M4.o: In function `mysql_perform_query(st_mysql*, char*)':
test.c:(.text+0xa2): undefined reference to `mysql_query'
test.c:(.text+0xb6): undefined reference to `mysql_error'
test.c:(.text+0xdd): undefined reference to `mysql_use_result'
/tmp/ccHFL1M4.o: In function `main':
test.c:(.text+0x170): undefined reference to `mysql_fetch_row'
test.c:(.text+0x18c): undefined reference to `mysql_free_result'
test.c:(.text+0x198): undefined reference to `mysql_close'
collect2: ld returned 1 exit status

I believe i have done everything right.. can you guys please point out where I am mistaken

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:45:28+00:00Added an answer on May 28, 2026 at 4:45 am

    You have to actually link the library as well (-I just specifies the include directory).

    Try

    g++ -I/usr/include/mysql -I/usr/include/mysql++ -L/usr/local/lib -lmysqlpp -lmysqlclient test.c
    

    Here’s a sample makefile for you.

    Here’s a sample command line for separate compilation steps (creates object files first, then links them together):

    g++ -I/usr/include/mysql -I/usr/include/mysql++ -o test.o -c test.c
    g++ -L/usr/local/lib -lmysqlpp -lmysqlclient -o test test.o
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get away from using Mamp, so have recently installed mysql, edited
I have MySQL installed on a Windows 2003 server on our domain. I cannot
I have a fairly small MySQL database (a Textpattern install) on a server that
I have installed MySQL server 5 on redhat linux. I can't login as root
We have installed OpenDataKit (ODK) Aggregate and we are using a MySQL Database. I
I have installed nodejs and mysql(also the work bench) I am building a server
I have installed native apache and mysql,php in my linux server. I tried a
I have installed mysql on a mac 10.7, I am using phpmyadmin to access
I had earlier installed mysql-5.1.50-osx10.6-x86_64.dmg and then uninstalled it using the below belo command
I have installed mysql v5.5.17 in linux using yum, now i want default lowercase

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.