Linux 链接MySQL出错 undefined reference to `mysql_init'

来源:互联网 发布:验证码 源码 编辑:程序博客网 时间:2024/06/06 09:12

今天用Linux编译socket的通信程序,出现以下错误,折腾了整整一天,重要解决!!!


/tmp/ccebULYF.o: In function `main':

tcp_demo.cpp:(.text+0x494): undefined reference to `mysql_init'

tcp_demo.cpp:(.text+0x4d6): undefined reference to `mysql_real_connect'

tcp_demo.cpp:(.text+0x4fe): undefined reference to `mysql_query'

tcp_demo.cpp:(.text+0x5a0): undefined reference to `mysql_query'

tcp_demo.cpp:(.text+0x5bf): undefined reference to `mysql_store_result'

tcp_demo.cpp:(.text+0x5d5): undefined reference to `mysql_free_result'

tcp_demo.cpp:(.text+0x5e4): undefined reference to `mysql_close'

collect2: error: ld returned 1 exit status


其实答案也是在网上找的:https://ubuntuforums.org/showthread.php?t=1666018

原文看着比较费劲,我也是找了很久的资料,最后总结如下:

只需输入命名:

<span style="font-size:14px;">gcc -o test tcp_demo.c `mysql_config --cflags --libs`</span>

记得复制该命令,记得复制该命令,记得复制该命令,重要的事情说三遍。

因为`mysql_config --cflags --libs`的` `不是单引号,可能会弄错。

之后可以把 test 和tcp_demo.c改成自己的文件,然后执行就OK了

0 0