Sam大叔
"if you ever want something badly,let it go.if it comes back to you,then it's yours forever.if it doesn't,then it was never yours to begin with."

导航

 

Mac OS X下Qt的mySQL driver编译安装

原创文章,采用CC协议发布,转载请注明: 转载自canX.me

本文链接地址: Mac OS X下Qt的mySQL driver编译安装

– — – — – — – — – — – — – — – — – — – — – — – — – — – — – — – — – –

装个插件装一天的人你伤不起啊!

其实说起来过程也简单…但是因为文档和实际情况有出入,折腾了这么久…

下面是step by step:

1.下载Qt的源代码,假设放在$QtDir里.并且确保电脑上已经装上mySQL了,如果你和我一样用安装包安装的话,mySQL应该是装在/usr/local/mysql的.要搞清楚这些文件的存放位置,下面要用到

2.在终端上定位到$QtDir/src/plugins/sqldrivers/mysql/下,输入(根据mySQL的安装位置不同,下面的include和libs的路径可能需要修改):

1 qmake "INCLUDEPATH+=/usr/local/mysql/include" "LIBS+=-L/usr/local/mysql/lib -lmysqlclient_r" mysql.pro -spec macx-g++ CONFIG+=build_all
2 make
3 make install

编译时可能会有类似这样的warning:

1 ld: warning: directory '/tmp/qt-stuff-6474/source/qt-everywhere-opensource-src-4.7.0/lib' following -L not found
2 ld: warning: directory '/tmp/qt-stuff-6474/source/qt-everywhere-opensource-src-4.7.0/lib' following -F not found

但这确实只是个warning而已

3.定位到/Developer/Applications/Qt/plugins/sqldrivers,这个也是用安装包安装时Qt的SQL driver默认位置(按情况修改),输入:

1 rm libqsqlmysql_debug.dylib
2 install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib libqsqlmysql.dylib

上面mySQL client的版本也要按需更改,需要的版本这样查看:

1 otool -L libqsqlmysql.dylib

完毕.

主要的经验有,以后在mac下用qmake要加参数-spec macx-g++,明确了各种include和libs的位置在哪里,以及…mac用户真是伤不起啊!windows有各种详细的step by step,linux用户估计直接apt-get神马的就可以…

好了,现在mac用户也有了…

读到第几句你心动了?看到哪里让你泪流满面?

posted on 2013-12-26 14:25  Sam大叔  阅读(4799)  评论(1编辑  收藏  举报