• Mac m1下Qt6.2.4的Mysql驱动插件编译配置和加载


    编译驱动插件参考如下:

    Mac Qt 6.2.2 MySQL驱动_U3_Bono的博客-CSDN博客

    我遇到的问题:执行$cmake --build . 时出现Failed

    [1/1] Linking CXX shared module plugins/sqldrivers/libqsqlmysql.dylib

    FAILED: plugins/sqldrivers/libqsqlmysql.dylib

    : && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -g -DNDEBUG -O2 -arch x86_64 -isysroot /Users/XXX/Qt/6.2.4/macos/lib/QtCore.framework/Versions/A/QtCore  -framework DiskArbitration  -framework IOKit && cd /Users/XXX/build-sqldrivers/mysql && /Users/XXX/Qt/Tools/CMake/CMake.app/Contents/bin/cmake -E make_directory /Users/XXX/bsqldrivers/plugins/sqldrivers/libqsqlmysql.dylib.dSYM/Contents/Resources/DWARF/qsqlmysql

    ld: warning: ignoring file /usr/local/mysql-8.0.30-macos12-arm64/lib/libmysqlclient.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64

    Undefined symbols for architecture x86_64:

    可以看到,Mac的m1款其架构师arm64,而不是X86_64,但是在build的时候显示在X86_64架构下,因此我前去寻找办法,经过一系列探索得到:

    编辑~/build-sqldrivers/build-ninja文件

    vim build-ninja

    修改build配置,把所有出现-arch x86_64的地方更改成 -arch arm64(记住是所有)

    如下:

    build mysql/CMakeFiles/QMYSQLDriverPlugin.dir/QMYSQLDriverPlugin_autogen/mocs_compilation.cpp.o: CXX_COMPILER__QMYSQLDriverPlugin_RelWithDebInfo /Users/XXX/build-sqldrivers/mysql/QMYSQLDriverPlugin_autogen/mocs_compilation.cpp || cmake_object_order_depends_target_QMYSQLDriverPlugin

      DEFINES = -DGL_SILENCE_DEPRECATION -DQMYSQLDriverPlugin_EXPORTS -DQT_CORE_LIB -DQT_DEPRECATED_WARNINGS -DQT_DEPRECATED_WARNINGS_SINCE=0x060000 -DQT_DISABLE_DEPRECATED_BEFORE=0x050000 -DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_NO_DEBUG -DQT_NO_EXCEPTIONS -DQT_NO_JAVA_STYLE_ITERATORS -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_PLUGIN -DQT_SQL_LIB -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE

      DEP_FILE = mysql/CMakeFiles/QMYSQLDriverPlugin.dir/QMYSQLDriverPlugin_autogen/mocs_compilation.cpp.o.d

      FLAGS = -g -DNDEBUG -O2 -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -mmacosx-version-min=12.0 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -fno-exceptions -fapplication-extension -std=c++17         

    build mysql/CMakeFiles/QMYSQLDriverPlugin.dir/qsql_mysql.cpp.o: CXX_COMPILER__QMYSQLDriverPlugin_RelWithDebInfo /Users/XXX/Qt/6.2.4/Src/qtbase/src/plugins/sqldrivers/mysql/qsql_mysql.cpp || cmake_object_order_depends_target_QMYSQLDriverPlugin

      DEFINES = -DGL_SILENCE_DEPRECATION -DQMYSQLDriverPlugin_EXPORTS -DQT_CORE_LIB -DQT_DEPRECATED_WARNINGS -DQT_DEPRECATED_WARNINGS_SINCE=0x060000 -DQT_DISABLE_DEPRECATED_BEFORE=0x050000 -DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_NO_DEBUG -DQT_NO_EXCEPTIONS -DQT_NO_JAVA_STYLE_ITERATORS -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_PLUGIN -DQT_SQL_LIB -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE

      DEP_FILE = mysql/CMakeFiles/QMYSQLDriverPlugin.dir/qsql_mysql.cpp.o.d

      FLAGS = -g -DNDEBUG -O2 -arch arm64 -isysroot

     

    # Link the shared module plugins/sqldrivers/libqsqlmysql.dylib

    build plugins/sqldrivers/libqsqlmysql.dylib: CXX_MODULE_LIBRARY_LINKER__QMYSQLDriverPlugin_RelWithDebInfo mysql/CMakeFiles/QMYSQLDriverPlugin.dir/QMYSQLDriverPlugin_autogen/mocs_compilation.cpp.o mysql/CMakeFiles/QMYSQLDriverPlugin.dir/main.cpp.o mysql/CMakeFiles/QMYSQLDriverPlugin.dir/qsql_mysql.cpp.o | /usr/local/mysql-8.0.30-macos12-arm64/lib/libmysqlclient.dylib || mysql/QMYSQLDriverPlugin_autogen mysql/QMYSQLDriverPlugin_autogen_timestamp_deps

      ARCH_FLAGS = -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -mmacosx-version-min=12.0

    如果单独更改 Link the shared module plugins/sqldrivers/libqsqlmysql.dylib时的-arch arm64会出现:虽然在/Users/XXX/Qt/6.2.4/macos/plugins/sqldrivers编译出了mysql的插件libqsqlmysql.dylib,但是最后无法正确链接,出现Qt creater无法加载的情况!!!!

  • 相关阅读:
    DRM全解析 —— ADD_FB2(0)
    腾讯云真的是良心云!服务器带宽、CPU、硬盘IO性能大揭秘!
    crypto:丢失的MD5
    一、Helm 3 简介
    STC51单片机学习笔记7——stc12c56 串口显示AD(单路ad+led指示灯)
    Linux基本配置与用户创建
    Java实现PDF文字内容识别,结合OCR实现PDF图片实现
    pyCharm导入pyspark中的sparkconf和sparkcontext错误
    《Mycat分布式数据库架构》之搭建详解
    “萌系小家电”顶流的小熊电器,如何创造全域增长?
  • 原文地址:https://blog.csdn.net/zhichi_yan/article/details/126318636