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 change

    The macOs is Sierra
    I built Qt from the online installer
    Qt 5.8

    This is very frustrating.. thanks for any assistance


  • Lifetime Qt Champion

    Hi,

    How did you install MySQL ?



  • Hello and thanks..

    I downloaded and installed the community server for mac (then set it to running)
    then I downloaded workbench for mac and connected. Everything appears to works from that side. I can see my database's.


  • Lifetime Qt Champion

    So you used the packages provided on the MySQL site ?



  • yes, I have never built from binaries



  • This is what I downloaded (if it helps)

    server 5.7.18 mac os dmg archive
    workbench 6.3.9 mac os dmg archive


  • Lifetime Qt Champion

    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.



  • I just tried that, and no luck gave the same error for '-lmysqlclient' :(


  • Lifetime Qt Champion

    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.



  • This post is deleted!


  • 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


  • Lifetime Qt Champion

    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

  • Lifetime Qt Champion

    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


  • Lifetime Qt Champion

    Don't remove it, updated it, see the condition part.

    You should also cleanup your build folder and try to build from scratch.



  • ok do you mean:

     { "libs": "-lmysqlclient_r", "condition": "-lmysqlclient" },   ?
    

    because I have no idea whats going on here tbh


  • Lifetime Qt Champion

    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.



  • That's ok. Is there anything else I can try? this is really stressing me out, and I am still searching the web for other solutions... one is homebrew but I don't know if I should or not. What do you think?


  • Lifetime Qt Champion

    Personally I usually use macports which is a homebrew equivalent to get my dependencies on macOS but both are fine.



  • Thanks for that. I shall leave you in peace for a while as I explore them and see how things turn out, and thanks so much for your help so far. I really appreciate it.



  • YEEAAH!

    After another 2 days of battling, I FINALLY got it working. I had totally given up on the conventional method of doing this for mac, as it was getting me no where. I still cannot for the life of me understand why Qt didn't load this very popular driver in the release and why building this driver on mac is so difficult when I had previously got it working on windows the conventional way much easier (thanks to @SGaist and others).

    Anyway Homebrew worked by installing Qt and MySql together: (this takes a very long time)

    brew install qt5 --with-mysql
    

    after that installed Qt creator:

    brew cask install qt-creator
    

    then configured MySql as normal through terminal as it seems you can't get sysprefpane this way.

    Hopefully this can help others, and a big thanks to @SGaist for taking the time!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.