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

  • SEARCH
  • Home
  • 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 7656707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:50:12+00:00 2026-05-31T12:50:12+00:00

I am writing some code in C which connects to MYSQL server. I am

  • 0

I am writing some code in C which connects to MYSQL server. I am using Netbeans and new to this. I configured it as directed and installed MYSQL Connector C. I also installed CYGWIN GCC, G++, GDB, MAKE from cygwin site. I created a c project and in the properties-> build-> c compiler->Include directories, set the path of mysql connector (C:\Program Files\MySQL\Connector C 6.0.2\include). Now i write some code to interect with MYSQL server, on build some error occurs.

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


int main(int argc, char** argv) {   


MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "root";
char *password = "aaaa"; /* set me first */
char *database = "mysql";
conn = mysql_init(NULL);
/* Connect to database */
if (!mysql_real_connect(conn, server,
     user, password, database, 0, NULL, 0)) {
  fprintf(stderr, "%s\n", mysql_error(conn));
  exit(1);
}
/* send SQL query */
if (mysql_query(conn, "show tables")) {
  fprintf(stderr, "%s\n", mysql_error(conn));
  exit(1);
}
res = mysql_use_result(conn);
/* output table name */
printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
  printf("%s \n", row[0]);
/* close connection */
mysql_free_result(res);
mysql_close(conn);

return (EXIT_SUCCESS);
}

After build following error occurs:

build/Debug/Cygwin-Windows/main.o: In function `main':
/cygdrive/c/Documents and Settings/AEM/My     Documents/NetBeansProjects/CppApplication_2/main.c:26: undefined reference to `_mysql_init'
/cygdrive/c/Documents and Settings/AEM/My    Documents/NetBeansProjects/CppApplication_2/main.c:28: undefined reference to     `_mysql_real_connect'
/cygdrive/c/Documents and Settings/AEM/My    Documents/NetBeansProjects/CppApplication_2/main.c:30: undefined reference to   `_mysql_error'
/cygdrive/c/Documents and Settings/AEM/My    Documents/NetBeansProjects/CppApplication_2/main.c:34: undefined reference to   `_mysql_query'
/cygdrive/c/Documents and Settings/AEM/My Documents/NetBeansProjects/CppApplication_2/main.c:35: undefined reference to `_mysql_error'
/cygdrive/c/Documents and Settings/AEM/My  Documents/NetBeansProjects/CppApplication_2/main.c:38: undefined reference to `_mysql_use_result'
/cygdrive/c/Documents and Settings/AEM/My   Documents/NetBeansProjects/CppApplication_2/main.c:41: undefined reference to   `_mysql_fetch_row'
/cygdrive/c/Documents and Settings/AEM/My Documents/NetBeansProjects/CppApplication_2/main.c:44: undefined reference to `_mysql_free_result'
/cygdrive/c/Documents and Settings/AEM/My  Documents/NetBeansProjects/CppApplication_2/main.c:45: undefined reference to `_mysql_close'
make[2]: Leaving directory `/cygdrive/c/Documents and Settings/AEM/My   Documents/NetBeansProjects/CppApplication_2'
make[1]: Leaving directory `/cygdrive/c/Documents and Settings/AEM/My   Documents/NetBeansProjects/CppApplication_2'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/Cygwin-Windows/cppapplication_2.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2


BUILD FAILED (exit value 2, total time: 1s)

I googled a lot but could not find anything to solve this issue. Need Help.

  • 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-31T12:50:14+00:00Added an answer on May 31, 2026 at 12:50 pm

    add -lmysql to link with the mysql library (valid for gcc). Or, if you use another Compiler, tell the Compiler

    • where the Libs are (add the Path)
    • to link the Library to the executable. This is something different, then adding the Path.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I m writing some code which retrieves info about installed apps, especially defined models,
I'm currently writing some code which will download images from my web server for
I'm writing some code which could really do with some simple compile time metaprogramming.
I'm writing some code which involves running a few shell commands from Python and
I am writing some code in which i need to get a line from
I'm writing a JUnit test for some code that produces an Excel file (which
I am writing java code. which will work on windows and linux. some code
I'm currently writing a piece of code that does some searches which returns IDisposable
I'm writing code to download email from various servers, some of which are outside
I am writing some code to type strings using the Robot class. Everything is

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.