Menu

linking problem with devcpp using mysql.h

2009-11-27
2012-09-26
  • György Zelena

    György Zelena - 2009-11-27

    hello!
    i'm using WinXP PRO and i would like to insert data from c code to mysql
    database. i installedDEV-C++ 4.9.7.0 version, devpack 5.0.5, and mysql5.1
    server. icreate the libmysql.a file with reimp and dlltool, and sopy to
    devcpp/lib directory. I copy libmysql.dll to windows/system32. in liker option
    i wrote -lmysql and in include libraries the dev-cpp/include/mysql path.
    i check the libmysql.a file it contains mysql_init@4 but when i compile my
    program i have an error message:
    undefined reference to `mysql_init@4'
    Could yuo help me?
    Thank you: Zelena György

     
  • cpns

    cpns - 2009-11-27

    Post the whole "Compile Log" text. Post it with code mark-up, otherwise it
    will get garbled - use the preview pane below the composition box to see the
    wysiwyg version of your text, you should get somethinglike this.

     
  • György Zelena

    György Zelena - 2009-11-27

    my program from internet source:

       
    #include <stdlib.h>  
    #include <stdio.h>  
    #include <stdio.h>
    
    #include <windows.h>  
    #include <mysql/mysql.h>  
    
    static char *opt_host_name = "localhost"; /* server host (default=localhost)
    */  
    static char *opt_user_name = "root"; /* username (default=login name) */  
    static char *opt_password = ""; /* password (default=none) */  
    static unsigned int opt_port_num = 3306; /* port number (use built-in value)
    */  
    static char *opt_socket_name = NULL; /* socket name (use built-in value) */  
    static char *opt_db_name = "mysql"; /* database name (default=none) */  
    static unsigned int opt_flags = 0; /* connection flags (none) */  
    
    int main (int argc, char *argv)  
    {  
    MYSQL *conn; /* pointer to connection handler */  
    MYSQL_RES *res; /* holds the result set */  
    MYSQL_ROW row;  
    
    /* initialize connection handler */  
    conn = mysql_init(NULL);  
    
    /* connect to server */  
    mysql_real_connect (conn, opt_host_name, opt_user_name, opt_password,  
    opt_db_name, opt_port_num, opt_socket_name, opt_flags);  
    
    /* show tables in the database (test for errors also) */  
    if(mysql_query(conn, "show tables"))  
    {  
    fprintf(stderr, "%s \n", mysql_error(conn));  
    printf("Press any key to continue. . . ");  
    getch();  
    exit(1);  
    }  
    
    res = mysql_use_result(conn); /* grab the result */  
    
    printf("Tables in database\n");  
    while((row = mysql_fetch_row(res)) != NULL)  
    printf("%s \n", row);  
    
    /* disconnect from server */  
    mysql_close (conn);  
    
    printf("Press any key to continue . . . ");  
    getch();  
    return 0;  
    } /* end main function */  
    
     

    the compile log:

      

    Compiler: Default compiler
    Building Makefile: "C:\Dev-Cpp\mysqlProba\Makefile.win"
    Executing make...
    make.exe -f "C:\Dev-Cpp\mysqlProba\Makefile.win" all
    gcc.exe -c main.c -o main.o -I"C:/Dev-Cpp/include" -I"C:/Dev-
    Cpp/include/mysql"

    gcc.exe main.o -o "mysqlProba.exe" -L"C:/Dev-Cpp/lib" -I"C:/Dev-Cpp/include"
    -I"C:/Dev-Cpp/include/mysql"

    main.o(.text+0xb5):main.c: undefined reference to mysql_init@4' main.o(.text+0xf0):main.c: undefined reference tomysql_real_connect@32'
    main.o(.text+0x101):main.c: undefined reference to mysql_query@8' main.o(.text+0x119):main.c: undefined reference tomysql_error@4'
    main.o(.text+0x164):main.c: undefined reference to mysql_use_result@4' main.o(.text+0x188):main.c: undefined reference tomysql_fetch_row@4'
    main.o(.text+0x1bc):main.c: undefined reference to `mysql_close@4'

    make.exe: *** Error 1

    Execution terminated

    in compiler options i wrote (into Add these comand into linker command line):
    -lmysql

    i have been working to solve this problem for several days but i think i
    havent enough experience. (i'm a student and i'm vorking on my diploma work)

    thank you for your help: Zelena György

     
  • cpns

    cpns - 2009-11-27

    Like I said; post the log in code mark-up, and check the formatting with the
    preview; close but no cigar! ;-) Never mind; no one leshe has got it right
    since the formatting feature was added either!

    in compiler options i wrote (into Add these comand into linker command
    line): -lmysql

    Yet if you look at the command line in the Compile Log, you'll see that
    option does not appear. The problem is that The "Tools->Compiler options"
    dialog sets values that are applied to new projects. Once you have created a
    project, most of those options are ignored. You need to add project specific
    options to the project options dialog (Project->Project options). This is a
    similar dialog, but for the current project.

     
  • György Zelena

    György Zelena - 2009-11-30

    Dear cpns!

    It works!!!!
    Thank you for your help!! You save my life!

    zelena György

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.