Home  >  Article  >  Database  >  在LInux上安装:mysql C connector :How to install MySQL Co

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

WBOY
WBOYOriginal
2016-06-07 15:02:301335browse

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

 






Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn