|
|
开始学习LINUX C编程,写了段查询MYSQL的程序老编不过去,不知道是哪儿的问题?在公司RH AS上就可以,那个上面MYSQL应该是系统自带的老版本的。
自己机器上MYSQL是mysql-max-5.0.27-linux-i686-glibc23.tar.gz
下面三段出错代码分别是三条命令的结果 ,代码第一行是命令。
- gcc -g -o mycreate mycreate.c -I/usr/local/mysql/include -L/usr/local/mysql/lib -lmysqlclient
- /usr/local/mysql/lib/libmysqlclient.a(my_compress.o): In function `my_compress_alloc':my_compress.c:(.text+0xc5):对‘compress’未定义的引用
- /usr/local/mysql/lib/libmysqlclient.a(my_compress.o): In function `my_uncompress':my_compress.c:(.text+0x14c):对‘uncompress’未定义的引用
- /usr/local/mysql/lib/libmysqlclient.a(libtaocrypt_la-dh.o): In function `TaoCrypt::(anonymous namespace)::DiscreteLogWorkFactor(unsigned int)':dh.cpp:(.text+0x8c):对‘pow’未定义的引用
- :dh.cpp:(.text+0xa6):对‘log’未定义的引用
- :dh.cpp:(.text+0xae):对‘pow’未定义的引用
- /usr/local/mysql/lib/libmysqlclient.a(libtaocrypt_la-dh.o): In function `TaoCrypt::DH::GenerateKeyPair(TaoCrypt::RandomNumberGenerator&, unsigned char*, unsigned char*)':dh.cpp:(.text+0x2d1):对‘pow’未定义的引用
- :dh.cpp:(.text+0x2ee):对‘log’未定义的引用
- :dh.cpp:(.text+0x2f6):对‘pow’未定义的引用
- /usr/local/mysql/lib/libmysqlclient.a(libtaocrypt_la-dh.o): In function `TaoCrypt::DH::GeneratePrivate(TaoCrypt::RandomNumberGenerator&, unsigned char*)':dh.cpp:(.text+0x488):对‘pow’未定义的引用
- :dh.cpp:(.text+0x4a9):对‘log’未定义的引用
- :dh.cpp:(.text+0x4b1):对‘pow’未定义的引用
- collect2: ld returned 1 exit status
复制代码
- gcc -g -o mycreate mycreate.c -I/usr/local/mysql/include -L/usr/local/mysql/lib -lmysqlclient -lz
- /usr/local/mysql/lib/libmysqlclient.a(libtaocrypt_la-dh.o): In function `TaoCrypt::(anonymous namespace)::DiscreteLogWorkFactor(unsigned int)':dh.cpp:(.text+0x8c):对‘pow’未定义的引用
- :dh.cpp:(.text+0xa6):对‘log’未定义的引用
- :dh.cpp:(.text+0xae):对‘pow’未定义的引用
- /usr/local/mysql/lib/libmysqlclient.a(libtaocrypt_la-dh.o): In function `TaoCrypt::DH::GenerateKeyPair(TaoCrypt::RandomNumberGenerator&, unsigned char*, unsigned char*)':dh.cpp:(.text+0x2d1):对‘pow’未定义的引用
- :dh.cpp:(.text+0x2ee):对‘log’未定义的引用
- :dh.cpp:(.text+0x2f6):对‘pow’未定义的引用
- /usr/local/mysql/lib/libmysqlclient.a(libtaocrypt_la-dh.o): In function `TaoCrypt::DH::GeneratePrivate(TaoCrypt::RandomNumberGenerator&, unsigned char*)':dh.cpp:(.text+0x488):对‘pow’未定义的引用
- :dh.cpp:(.text+0x4a9):对‘log’未定义的引用
- :dh.cpp:(.text+0x4b1):对‘pow’未定义的引用
- collect2: ld returned 1 exit status
复制代码
- gcc -g -o mycreate mycreate.c -I/usr/local/mysql/include -L/usr/local/mysql/lib -lmysqlclient -lm
- /usr/local/mysql/lib/libmysqlclient.a(my_compress.o): In function `my_compress_alloc':my_compress.c:(.text+0xc5):对‘compress’未定义的引用
- /usr/local/mysql/lib/libmysqlclient.a(my_compress.o): In function `my_uncompress':my_compress.c:(.text+0x14c):对‘uncompress’未定义的引用
- collect2: ld returned 1 exit status
复制代码
程序代码如下:
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- //#include "mysql/mysql.h"
- #include "mysql.h"
- int main()
- {
- MYSQL *ssock;
- char sql[500];
- MYSQL_RES *sel_result = NULL;
- int i;
-
- ssock = (MYSQL *)malloc(sizeof(MYSQL));
- mysql_init(ssock);
- if (!(mysql_real_connect(ssock,"localhost","root","eaps0543","test_woody",0,NULL,0)))
- {
- printf("Cannot connect to the mysql server.Error: %s\n",mysql_error(ssock));
- exit(-1);
- }
-
- sprintf(sql,"SELECT * FROM girls LIMIT 10");
-
- i = mysql_real_query(ssock,sql,strlen(sql));
-
- sel_result = mysql_store_result(ssock);
-
- while(sel_result->data_cursor)
- {
- printf("Name:%10s,age:%d\n",
- sel_result->data_cursor->data[1],
- atoi(sel_result->data_cursor->data[2]));
-
- sel_result->data_cursor = sel_result->data_cursor->next;
- }
-
- printf("\n\t\t%d records affected\n",sel_result->row_count);
- mysql_free_result(sel_result);
- return 0;
-
- }
复制代码 |
|