GCC编译不会和运行MySQL C库 [英] gcc wont compile and run MySQL C libraries

查看:470
本文介绍了GCC编译不会和运行MySQL C库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 的#include< my_global.h>
#包括LT&;&mysql.h中GT;INT主(INT ARGC,字符** argv的)
{
  的printf(MySQL的客户端版本:%S \\ n,mysql_get_client_info());
}


  

〜$ gcc的-o的mysql-测试MySQL-TEST.C


我尝试从终端执行该测试程序,但得到以下错误消息:

/tmp/cceEmI0I.o:在功能主要:在MySQL-TEST.C :(文字+为0xA):未定义引用 mysql_get_client_info

什么是错的?我的系统是Ubuntu的


解决方案

的MySQL 自带了一个叫做特殊的脚本 mysql_config 。它为您提供了编译MySQL客户端并连接到MySQL数据库服务器的有用信息。

- 库选项 - 与MySQL客户端库进行链接所需的库和选项

  $ mysql_config --libs

典型输出:

  -L在/ usr / lib64下/ mysql的-lmysqlclient -lz -lcrypt -lnsl -lm -L在/ usr / lib64下-lssl -lcrypto

现在,您可以添加到您的编译/链接行:

  GCC -o MySQL的测试的MySQL TEST.C $(mysql_config --libs)

#include <my_global.h>
#include <mysql.h>

int main(int argc, char **argv)
{
  printf("MySQL client version: %s\n", mysql_get_client_info());
}

~$ gcc -o mysql-test MySQL-Test.c

im trying to execute this test program from terminal but get the following error message:

/tmp/cceEmI0I.o: In function main': MySQL-Test.c:(.text+0xa): undefined reference tomysql_get_client_info'

what is wrong? my system is ubuntu

解决方案

MySQL comes with a special script called mysql_config. It provides you with useful information for compiling your MySQL client and connecting it to MySQL database server.

Pass --libs option - Libraries and options required to link with the MySQL client library.

$ mysql_config --libs

Typical Output:

-L/usr/lib64/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -L/usr/lib64 -lssl -lcrypto

Now you can add this to your compile/link line:

gcc -o mysql-test MySQL-Test.c $(mysql_config --libs)

这篇关于GCC编译不会和运行MySQL C库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆