ld: library not found for -lmysqlclient_r (when trying to build mysql driver on mac)
-
Hi guys
Disclaimer: I am a windows person, and not very good at mac os...
But now a situation has arisen where I do need to use mac in depth so it's all new to me. After running qmake in the mysql directory, I get the 'ld: library not found for -lmysqlclient_r' error when running make. The qmake cmd I run is:
qmake "INCLUDEPATH+=/usr/local/mysql/include" "LIBS+=-L/usr/local/lib -lmysqlclient_r" mysql.pro
The contents of lib folder:
libmysqlclient.20.dylib libmysqld-debug.a libmysqlclient.dylib libmysqlservices.a libmysqlclient.a libmysqld.a mecab pkgconfig plugin
This is the make output:
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f Makefile.Release all rm -f libqsqlmysql.dylib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -stdlib=libc++ -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.9 -Wl,-rpath,@loader_path/../../lib -single_module -dynamiclib -o libqsqlmysql.dylib .obj/release/qsql_mysql.o .obj/release/main.o .obj/release/moc_qsql_mysql_p.o -F/Users/ldigital/Qt/5.8/clang_64/lib -L/usr/local/lib -framework QtSql -framework QtCore -framework DiskArbitration -framework IOKit -L/opt/local/lib/mysql55/mysql -lmysqlclient_r -lz ld: warning: directory not found for option '-L/opt/local/lib/mysql55/mysql' ld: library not found for -lmysqlclient_r clang: error: linker command failed with exit code 1 (use -v to see invocation) make[1]: *** [../../../../plugins/sqldrivers/libqsqlmysql.dylib] Error 1 make: *** [release-all] Error 2
Im not sure, but It looks like the path to lmysqlclient_r is wrong (i do not have /opt/local/lib/mysql55/mysql )
After some checking around, and seeing similar posts, otool and install_name_tool may be the answer, but I don't know which file in my lib to check for dependencies, and what path to changeThe macOs is Sierra
I built Qt from the online installer
Qt 5.8This is very frustrating.. thanks for any assistance
-
Hi,
How did you install MySQL ?
-
So you used the packages provided on the MySQL site ?
-
This is what I downloaded (if it helps)
server 5.7.18 mac os dmg archive
workbench 6.3.9 mac os dmg archive -
Then replace
-lmysqlclient_r
with-lmysqlclient
.The _r means re-entrant but AFAIK, the latest versions of the client libraries should be re-entrant anyway.
-
You still need to give the linker the path where to find the librairies.
Add
LIBS += -L/path/to/MySQL_libs/
to your .pro file.
-
Hi sorry to be a pain, still not worked yet... If I've understood you I tried:
adding path to lib 'LIBS += -L/usr/local/mysql/lib' to my mysql.pro:
TARGET = qsqlmysql LIBS += -L/usr/local/mysql/lib <--- HEADERS += $$PWD/qsql_mysql_p.h SOURCES += $$PWD/qsql_mysql.cpp $$PWD/main.cpp QMAKE_USE += mysql OTHER_FILES += mysql.json PLUGIN_CLASS_NAME = QMYSQLDriverPlugin include(../qsqldriverbase.pri)
then run qmake cmd with '-lmysqlclient'
qmake "INCLUDEPATH+=/usr/local/mysql/include" "LIBS+=-L/usr/local/lib -lmysqlclient" mysql.pro
make
-
What exact error do you get this time ?
-
Now that you mentioned the error, I can see that it's still refering to '-lmysqlclient_r' even though I ran '-lmysqlclient'. I wonder what thats about? Here it is:
Last login: Sat May 27 23:01:02 on console Leons-Mac:~ ldigital$ cd Qt/5.8/Src/qtbase/src/plugins/sqldrivers/mysql Leons-Mac:mysql ldigital$ qmake "INCLUDEPATH+=/usr/local/mysql/include" "LIBS+=-L/usr/local/lib -lmysqlclient" mysql.pro Leons-Mac:mysql ldigital$ make /Applications/Xcode.app/Contents/Developer/usr/bin/make -f Makefile.Release all rm -f libqsqlmysql.dylib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -stdlib=libc++ -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.9 -Wl,-rpath,@loader_path/../../lib -single_module -dynamiclib -o libqsqlmysql.dylib .obj/release/qsql_mysql.o .obj/release/main.o .obj/release/moc_qsql_mysql_p.o -F/Users/ldigital/Qt/5.8/clang_64/lib -L/usr/local/lib -lmysqlclient -L/usr/local/mysql/lib -framework QtSql -framework QtCore -framework DiskArbitration -framework IOKit -L/opt/local/lib/mysql55/mysql -lmysqlclient_r -lz ld: warning: directory not found for option '-L/opt/local/lib/mysql55/mysql' ld: library not found for -lmysqlclient_r clang: error: linker command failed with exit code 1 (use -v to see invocation) make[1]: *** [../../../../plugins/sqldrivers/libqsqlmysql.dylib] Error 1 make: *** [release-all] Error 2
-
Edit
/qtbase/src/sql/configure.json
and change the library name. -
ok here is the libraries section for mysql in configure.json:
"mysql": { "label": "MySQL", "test": "unix/mysql", "sources": [ { "type": "mysqlConfig", "query": "--libs_r" }, { "type": "mysqlConfig", "query": "--libs" }, { "libs": "-lmysqlclient_r", "condition": "!config.win32" }, { "libs": "-llibmysql", "condition": "config.win32" }, { "libs": "-lmysqlclient", "condition": "!config.win32" } ] },
I removed (temporarily) the '-libmysqlclient_r' line seeing as '-libmysqlclient' is already there, and tried again but still gives the same error for -lmysqlclient_r
-
Don't remove it, updated it, see the condition part.
You should also cleanup your build folder and try to build from scratch.
-
I meant: just remove the _r. The condition basically states that this line apply all configurations that are not win32.
Note that I missed the one further down. So in fact, removing it was a correct solution, sorry for the confusion.