在LInux上安装:mysql C connector :How to install MySQL Co

php中文网
发布: 2016-06-07 15:02:30
原创
1546人浏览过

hey there, I'm writing an app in C that requires MySQL interaction, so I downloaded the Connector/C archive from the official website, and it contains bin, lib and include folders, but I don't know where to install them.I could copy the in

hey there,

I'm writing an app in C that requires MySQL interaction, so I downloaded the Connector/C archive from the official website, and it contains bin, lib and include folders, but I don't know where to install them.I could copy the include files into my project folder, but where can I put the lib file so that my compiled binary (and other binaries) can find it?

Thanks in advance!

 


 

答案:

the answer:

 

首先, 将 tar file,解压,然后:

其中位于lib 中的文件拷贝到 /usr/local/lib中

位于 include中的文件拷贝到 /usr/local/include中

位于bin中的文件拷贝到 /usr/local/bin 中;

注意: /usr/.. 文件夹可能时不可见的,所以,以上操作,要通通命令行来完成,祝你好运!

             其次,在编译时,不要忘了链接库的选项:

 

方法1:采用动态链接库编译:

采用动态链接库的编译:最后附上一个编译代码操作:

 gcc -o db.o db.c  -lmysql

 

 

方法2: 采用静态库来编译: (生成的文件可能比较大,嘿嘿 )

这个方法用动态连接库,比较那啥一点吧,看喜好,编译进去也行,2M多吧。

gcc -o db.o db.c  /usr/local/lib/libmysqlclient.a

 

方法3: 将连接器转入你的工程中

在你没有进行以上操作时,你也可以通过以下方法通过编译: 通过指定链接库的路径

gcc -o db.o db.c   -L mysql_connector_path/lib  -l mysql 

 

其中: mysql_connector_path 是你的mysql连接器所在的目录,通过 -L 选项来指定动态链接库的路径 ,这就是说通过在工程中包含该连接器目录,也能实现通过编译,更甚者把整个静态库都编译应用如方法2所采用的策略。

2 Answers

 

This is confusing, isn't it.. don't know why they don't make this more clear.

The lib/ files go in /usr/local/libThe include/ files go in /usr/local/includeThe bin/ files go in /usr/local/bin

The /usr/.. directory isn't visible through finder afaik so you have to go at it via commandline. Best of luck

Also, in your Xcode project, make sure you add a Linked Library by going to your Target's settings, General, then adding Linked Library "libmysqlclient.dylib"

 

 

 

 

 

Hey, on MySQL site you have a short presentation on how to install C connector for MySQL. You can access it here: http://dev.mysql.com/doc/refman/5.1/en/connector-c-building.html

 






相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号