[英]Mysql with C++ error: undefined reference to mysql_init
#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;
}
and i get linker error in codeblocks: 我在codeblocks中遇到链接器错误:
undefined reference to mysql_init
I used mysql_config --libs
in linker option and mysql_config --cflags
in compiler option. 我用mysql_config --libs
在连接选项和mysql_config --cflags
在编译器选项。
I read somewhere i should add some libraries like libmysql.lib, but i cannot find this file on my PC (I am using Ubuntu 11.04 64bit). 我在某处读到了我应该添加一些像libmysql.lib这样的库,但我在我的电脑上找不到这个文件(我使用的是Ubuntu 11.04 64bit)。
This is for Linux environments only: 这仅适用于Linux环境:
In "Project build options" > "Linker settings" Tab > Under "Other linker options" add -lmysqlclient 在“项目构建选项”>“链接器设置”选项卡>“其他链接器选项”下, 添加-lmysqlclient
You will also need to add mysql-connector-c-6.1.3-linux-glibc2.5-x86_64/include/ in "Search directories" > "Compiler" 您还需要在“搜索目录” > “编译器”中添加mysql-connector-c-6.1.3-linux-glibc2.5-x86_64 / include /
You will also need to add mysql-connector-c-6.1.3-linux-glibc2.5-x86_64/lib/ in "Search directories" > "Linker" 您还需要在“搜索目录” > “链接器”中添加mysql-connector-c-6.1.3-linux-glibc2.5-x86_64 / lib /
For windows: 对于Windows:
-lmysql -lmysql
MySQL Connector library can be found here: http://dev.mysql.com/downloads/connector/c/ MySQL Connector库可以在这里找到: http : //dev.mysql.com/downloads/connector/c/
使用命令bellow编译您的应用程序
gcc -o test -L/usr/lib/mysql -lmysqlclient test.c
设置 - >编译器和调试器 - >搜索目录 - >链接器然后添加并插入/usr/lib/mysql/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.