GCC编译不会和运行MySQL C库 [英] gcc wont compile and run MySQL C libraries
问题描述
的#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 to
mysql_get_client_info'what is wrong? my system is ubuntu
解决方案
MySQL
comes with a special script calledmysql_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屋!