gpt4 book ai didi

c++ - 带有 C++ 错误 : undefined reference to mysql_init 的 Mysql

转载 作者:可可西里 更新时间:2023-11-01 07:23:29 26 4
gpt4 key购买 nike

#include <stdlib.h>
#include <mysql.h>

#include <my_global.h>


int main (int argc, char *argv[])
{

MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;

char *server = "127.0.0.1";
char *user = "root";
char *password = "1386";
char *database = "OurDB";

conn = mysql_init(NULL);

/* Connect to database */
if (!mysql_real_connect(conn, server,user, password, database, 0, NULL, 0))
{
fprintf(stderr, "%s\n", mysql_error(conn));
exit(0);
}

return 0;
}

我在代码块中遇到链接器错误:

undefined reference to mysql_init

我在链接器选项中使用了 mysql_config --libs,在编译器选项中使用了 mysql_config --cflags

我在某处读到我应该添加一些库,如 libmysql.lib,但我在我的电脑上找不到这个文件(我使用的是 Ubuntu 11.04 64 位)。

最佳答案

这仅适用于 Linux 环境:

In "Project build options" > "Linker settings" Tab > Under "Other linker options" add -lmysqlclient

enter image description here

您还需要添加 mysql-connector-c-6.1.3-linux-glibc2.5-x86_64/include/“搜索目录”> “编译器”

enter image description here

您还需要添加 mysql-connector-c-6.1.3-linux-glibc2.5-x86_64/lib/“搜索目录”> “链接器”

enter image description here

对于窗口:

-lmysql

MySQL 连接器库可以在这里找到: http://dev.mysql.com/downloads/connector/c/

关于c++ - 带有 C++ 错误 : undefined reference to mysql_init 的 Mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9645844/

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