gpt4 book ai didi

c - 添加mysql客户端库出现段错误

转载 作者:行者123 更新时间:2023-11-30 00:51:14 25 4
gpt4 key购买 nike

#include<stdio.h>
#include<stdlib.h>
#include<mysql/mysql.h>
int main()
{
char *tempry;
tempry = (char *) malloc(20*sizeof(char));
sprintf(tempry,"hello");
printf("\n%s\n",tempry);
/* Here i can use mysql connectivity code */
return 0;
}

当我使用这个gcc test.c -o test -g gcc编译命令时,它会给我输出

hello

如果我使用这个gcc -I/usr/local/include -L/usr/lib64/mysql -lmysqlclient test.c -o test -g行那么它会给我此行中出现段错误错误

tempry =  (char *) malloc(20*sizeof(char));

最佳答案

检查您的mysql_real_connect()。您可能将 NULL 值传递给 mysql_real_connect()

mysql_init() 失败时返回NULL。那么您可以将此 NULL 传递给 mysql_real_connect(),从而导致段错误

mysql_init() Reference page

关于c - 添加mysql客户端库出现段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20948844/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com