CNL 回复于:2004-10-09 17:21:34 |
# l /usr/local/mysql/lib 确认库名是否正确
# grep mysql_real_connect /usr/local/mysql/include/*.h 确认头文件名是否无误 MYSQL *mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, uint port, const char *unix_socket, uint client_flag) 你是否少一个入参啊? |
sundy001 回复于:2004-10-09 17:27:43 |
已查证库名及头文件无误,函数已在头文件定义.
请教各位了.. |
CNL 回复于:2004-10-09 17:31:08 |
1、确认入参个数无误
2、把/usr/local/mysql/include及lib的文件名列出来看一下 |
sundy001 回复于:2004-10-09 17:40:44 |
======库文件====
# cd /usr # cd local # cd mysql # cd lib # pwd /opt/K/SKUNK98/Mysql/3.21.26/usr/local/mysql/lib # ls libdbug.a libmygcc.a libmysqlclient.a libmystrings.a libmysys.a =====头文件===== # cd .. # cd include # ls config.h dbug.h errmsg.h getopt.h global.h hash.h heap.h list.h m_ctype.h m_string.h merge.h my_alarm.h my_base.h my_dir.h my_nosys.h my_pthread.h my_sys.h mysql.h mysql_com.h mysql_version.h mysys_err.h nisam.h queues.h sched.h thr_alarm.h thr_lock.h tree.h ===========mysql.h 部分==== MYSQL *mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, unsigned int port,const char *unix_socket, |
CNL 回复于:2004-10-09 17:51:32 |
[quote:fe115ffb68]
conn = mysql_real_connect(&mysql, "localhost", "root", "haha",0,0,0); [/quote:fe115ffb68] 你写的入参不够。 |
sundy001 回复于:2004-10-09 19:14:03 |
不好意思,上贴 粘贴少了. mysql.h 得部分.
MYSQL *mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, unsigned int port,const char *unix_socket, unsigned int clientflag); 我引用的: conn = mysql_real_connect(&mysql, "localhost", "root", "haha",0,0,0); 两边都是7个参数. |
lw371 回复于:2004-10-09 19:21:55 |
比mysql资料少一个db参数
不过你这样试一下呢 cc -o test -I/usr/local/mysql/include test.c -L/usr/local/mysql/lib -lmysqlclient 我都是用gcc编译的,没有碰到你的问题: gcc -o test -I/usr/local/include test.c -L/usr/local/mysql/lib -lmysqlclient -lz |
sundy001 回复于:2004-10-09 20:46:36 |
用的是mysql 3。21。26版本。是少个DB参数。 |
sundy001 回复于:2004-10-10 20:30:24 |
谢谢各位,问题解决了。望今后能多多交流
下面是我的一些操作。希望指正 操作系统:sco openserver 5.0.5 数据库 :mysql 4.0.21 =========== mysql 4.0.21 安装部分 ===================================== 软件下载地: ftp://ftp2.sco.com//pub/skunkware/osr5/vols/ 安装: gzip-1.2.4-VOLS FSUpthreads-3.5-VOLS.tar make-3.78.1-VOLS.tar gcc-2.95.2-VOLS.tar #cp -p /usr/include/pthread/stdtypes.h /usr/local/lib/gcc-lib/i386-pc-sco3.2v5.0.5/2.95.2/include/pthread/ 更改系统搜索路径/.profile为: PATH=/usr/local/bin:/bin:/etc:/usr/bin:/tcb/bin 解压mysql-4.0.21.tar.gz #gzip -d mysql-4.0.21.tar.gz #tar xvf mysql-4.0.21.tar #cd mysql-4.0.21 #CFLAGS="-O3 –DSCO -mpentium" LDFLAGS=-static CXX=gcc CXXFLAGS="-O3 -DSCO -mpentium -felide-constructors" #./configure --prefix=/usr/local/mysql --with-charset=gb2312 --with-extra-charsets=complex --enable-thread-safe-client --enable-local-infile --with-named-z-libs=no --disable-shared --without-debug --without-isam --with-innodb #make #make install 如出现任何错误需要清理时: make clean(清除以前make出的文件 make uninstall(反安装) 建立mysql用户和组 建立mysql组 ID 100 建立mysql用户 ID 200 属mysql组 进入目录/usr/local/mysql/bin #chown mysql:mysql mysql 进入目录/usr/local #chown mysql:mysql mysql #su mysql $cd /usr/local/mysql/bin $./mysql_install_db $./mysqld_safe & 进入root用户 #加入搜索目录/.profile为: PATH=/usr/local/bin:/bin:/etc:/usr/bin:/tcb/bin:/usr/local/mysql/bin #ln -s /usr/local/mysql/bin/mysqld_safe /etc/rc2.d/S94mysql #reboot =========== ANSI C For mysql 4.0.21 编程部分 ===================================== 库目录和头文件目录: /usr/local/mysql/include/mysql /usr/local/mysql/lib/mysql 编译参数: gcc -L/usr/local/mysql/lib/mysql -I/usr/local/mysql/include/mysql -o test test.c -lmysqlclient -lsocket -lm ---------------------测试链接程序----------- #include "mysql.h" #include <stdio.h> main(){ MYSQL mysql; MYSQL_RES *res; MYSQL_ROW row; char *query; int t,r; /*初始化数据库连接句柄*/ mysql_init(&mysql); /*建立数据库连接*/ if (!mysql_real_connect(&mysql,"localhost","sundy", "haha","data",0,NULL,0)) { printf( "Error connecting to database: %s\n",mysql_error(&mysql)); } else printf("Connected...\n"); /*构造SQL查询语句*/ query="select * from data order by dataid desc"; /*执行查询*/ t=mysql_real_query(&mysql,query,(unsigned int) strlen(query)); if (t) { printf("Error making query: %s\n", mysql_error(&mysql)); } else printf("Query made...\n"); /*返回记录集*/ res=mysql_use_result(&mysql); for(r=0;r<=mysql_field_count(&mysql);r++){ row=mysql_fetch_row(res); if(row<0) break; for(t=0;t<mysql_num_fields(res);t++){ printf("%s ",row[t]); } printf("\n"); } /*关闭数据库连接*/ mysql_close(&mysql); } ----------------------------------------------- |
lw371 回复于:2004-10-11 14:41:45 |
多谢共享成果! |
zhuyuwen 回复于:2004-10-11 16:04:00 |
谢谢 |
qingxia 回复于:2004-10-12 14:56:07 |
/root/mysql/lib/libmysqlclient.a(my_compress.o)(.text+0xb4): In function `my_compress_alloc':
: undefined reference to `compress' /root/mysql/lib/libmysqlclient.a(my_compress.o)(.text+0x12a): In function `my_uncompress': : undefined reference to `uncompress' collect2: ld returned 1 exit status 这些是什么意思呢?我的机器里是出现这种错误 |
qingxia 回复于:2004-10-12 14:59:40 |
我的机器是red hat9.0
mysql5.0 代码为 #include <mysql.h> #include <stdio.h> main() { MYSQL mySql; mysql_init(&mySql); } gcc -o test test.c -lmysqlclient -L/root/mysql/lib |