|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Does any one know how to fix this compiling problem?
I´m new using MySQL so I took this source code to make some tests: #include <sys/time.h> #include <stdio.h> #include <mysql.h> int main (char **args) { MYSQL_RES *result; MYSQL_ROW row; MYSQL *connection, mysql; int state; /* connect to database */ mysql_init(&mysql); connection = mysql_real_connect(&mysql,"localhost","user","password","database", 0,0,0); /* check for connection error */ if (connection == NULL) { /* print error message */ printf(mysql_error(&mysql)); return 1; } state = mysql_query(connection, "SELECT x, y FROM tablename"); if (state != 0) { printf(mysql_error(connection)); return 1; } /* must call mysql_store_result() before we can issue any other * query calls */ result = mysql_store_result(connection); printf("Rows: %dn", mysql_num_rows(result)); /* process each row in result set */ while ((row = mysql_fetch_row(result)) != NULL) { printf("id: %s, val: %sn", (row[1] ? row[1] : "NULL"), (row[0] ? row[0] : "NULL")); } /* free the result set */ mysql_free_result(result); /* close the connection */ mysql_close(connection); printf("Done.n"); } When I compiling the error list are: Undefined first referenced symbol in file mysql_close test.o mysql_free_result test.o mysql_fetch_row test.o mysql_real_connect test.o mysql_store_result test.o mysql_query test.o mysql_init test.o ld: fatal: Symbol referencing errors. No output written to test The command is: $ /opt/SUNWspro/bin/cc -o test test.c -I/usr/local/mysql/include -L/usr/lib Does any one know how can I fix it? Please help, Adriana *********************** Finally I got the solution with this example: /***************************************************/ /* connect.c */ /* a simple connection test script */ /* Mysql C API */ /***************************************************/ #include <stdio.h> #include <mysql.h> #define def_hostname "localhost" #define def_username "your username in these quotes" #define def_password "your password in these quotes" #define def_dbName "your database name in these quotes" MYSQL *conn; int main(int argc, char *argv[]) { conn=mysql_init(NULL); if(conn==NULL) { fprintf(stderr, "mysql_init() failedn"); return 1; } if(mysql_real_connect(conn, def_hostname, def_username, def_password, def_dbName, 0, NULL, 0)==NULL) { fprintf(stderr, "mysql_real_connect() failed:nError %u (%s)n", mysql_errno(conn), mysql_error(conn)); return 1; } else { fprintf(stdout, "Connection to mysql server establishedn"); } mysql_close(conn); return 0; } And the compiling command: cc -c -I/usr/local/mysql/include connect.c} cc -o connect connect.o -L/usr/local/mysql/lib -lmysqlclient -lxnet -lm Regards, Adriana PS: Thank you Kyuzo for the hint [This message has been edited by adriana (edited June 13, 2000).] |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > Compiling problems!!! Help! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|