MacOS Catalina 从源码构建Qt6.2开发库之01: 编译Qt6.2源代码

安装xcode, cmake, ninja

brew install node

mac下安装OpenGL库并使之对各项目可见

在macOS上安装OpenGL通常涉及到安装一些依赖库,如MGL、GLUT或者是GLEW等,同时确保LLVM的OpenGL框架和相关工具链的兼容性。以下是一个基本的安装步骤,你可以在终端中执行:

  1. 安装 Homebrew (如果还没有安装的话):
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  2. 安装 MGL (Mac上的OpenGL开发库):
    brew install mgl
  3. 安装 GLUT (OpenGL Utility Toolkit):
    brew install freeglut

对于较旧的系统,你可能需要安装GLUT的较旧版本:
brew install freeglut --with-contrib
7.
8. 安装 GLEW (OpenGL Extension Wrangler Library):
brew install glew
9.
10. 配置你的项目
每个步骤之后,确保你的工作目录下有相应的头文件和库文件路径。你可以通过在.pro文件(对于Qt项目)或适当的地方设置C_INCLUDE_PATH和LIBRARY_PATH环境变量来设置路径。
11. 添加环境变量
export CPPFLAGS="-I/usr/local/opt/glew/include"
12. export LDFLAGS="-L/usr/local/opt/glew/lib"
13.

复制代码
如果你需要重复使用这些环境变量,可以将它们添加到你的.bash_profile或.zshrc文件中。
  1. 编译和链接你的程序
    在编译和链接你的OpenGL程序时,确保你的构建系统(如CMake、Makefile或IDE)能够找到这些库和头文件。

解压qt-everywhere-src-6.2.0.tar.xz到/Volumes/MacOS/Program/, 将目录名改为qt6.2.0

终端窗口进入/Volumes/MacOS/Program/qt6.2.0/,执行:

./configure

用CMake打开项目,设置安装目录为/us r/local

cmake ---build . ---parallel

修改 下面的 文件,明确链接OpenGL:

/Volumes/MacOS/Program/qt6.2.0/qtbase/src/plugins/platforms/cocoa/CMakeLists.txt

Generated from cocoa.pro.

special case:

#####################################################################

QCocoaIntegrationPlugin Plugin:

#####################################################################

找到 OpenGL 库

find_package(OpenGL REQUIRED)

qt_internal_add_plugin(QCocoaIntegrationPlugin

OUTPUT_NAME qcocoa

DEFAULT_IF ${QT_QPA_DEFAULT_PLATFORM} MATCHES cocoa # special case

PLUGIN_TYPE platforms

SOURCES

main.mm

qcocoaapplication.h qcocoaapplication.mm

qcocoaapplicationdelegate.h qcocoaapplicationdelegate.mm

qcocoabackingstore.h qcocoabackingstore.mm

qcocoaclipboard.h qcocoaclipboard.mm

qcocoacolordialoghelper.h qcocoacolordialoghelper.mm

qcocoacursor.h qcocoacursor.mm

qcocoadrag.h qcocoadrag.mm

qcocoaeventdispatcher.h qcocoaeventdispatcher.mm

qcocoafiledialoghelper.h qcocoafiledialoghelper.mm

qcocoafontdialoghelper.h qcocoafontdialoghelper.mm

qcocoahelpers.h qcocoahelpers.mm

qcocoainputcontext.h qcocoainputcontext.mm

qcocoaintegration.h qcocoaintegration.mm

qcocoaintrospection.h qcocoaintrospection.mm

qcocoamenu.h qcocoamenu.mm

qcocoamenubar.h qcocoamenubar.mm

qcocoamenuitem.h qcocoamenuitem.mm

qcocoamenuloader.h qcocoamenuloader.mm

qcocoamimetypes.h qcocoamimetypes.mm

qcocoanativeinterface.h qcocoanativeinterface.mm

qcocoansmenu.h qcocoansmenu.mm

qcocoascreen.h qcocoascreen.mm

qcocoaservices.h qcocoaservices.mm

qcocoasystemtrayicon.h qcocoasystemtrayicon.mm

qcocoatheme.h qcocoatheme.mm

qcocoawindow.h qcocoawindow.mm

qcocoawindowmanager.h qcocoawindowmanager.mm

qiosurfacegraphicsbuffer.h qiosurfacegraphicsbuffer.mm

qmacclipboard.h qmacclipboard.mm

qmultitouch_mac.mm qmultitouch_mac_p.h

qnsview.h qnsview.mm

qnswindow.h qnswindow.mm

qnswindowdelegate.h qnswindowdelegate.mm

qcocoacolordialoghelper.h qcocoacolordialoghelper.mm

qcocoafiledialoghelper.h qcocoafiledialoghelper.mm

qcocoafontdialoghelper.h qcocoafontdialoghelper.mm

DEFINES

QT_NO_FOREACH

LIBRARIES

${FWAppKit}

${FWCarbon}

${FWCoreServices}

${FWCoreVideo}

${FWIOKit}

${FWIOSurface}

${FWMetal}

${FWQuartzCore}

Qt::Core

Qt::CorePrivate

Qt::Gui

Qt::GuiPrivate

OpenGL::GL # 添加 OpenGL 库链接

)

special case begin

qt_disable_apple_app_extension_api_only(QCocoaIntegrationPlugin)

special case end

Resources:

set(qcocoaresources_resource_files

"images/sizeallcursor.png"

"images/spincursor.png"

"images/waitcursor.png"

)

qt_internal_add_resource(QCocoaIntegrationPlugin "qcocoaresources"

PREFIX

"/qt-project.org/mac/cursors"

FILES

${qcocoaresources_resource_files}

)

Keys ignored in scope 1:.:.:cocoa.pro:<TRUE>:

OTHER_FILES = "cocoa.json"

Scopes:

#####################################################################

qt_internal_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_opengl

SOURCES

qcocoaglcontext.h qcocoaglcontext.mm

LIBRARIES

OpenGL::GL # 添加OpenGL库

)

qt_internal_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_vulkan

SOURCES

qcocoavulkaninstance.h qcocoavulkaninstance.mm

LIBRARIES

OpenGL::GL # 添加OpenGL库

)

qt_internal_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_accessibility

SOURCES

qcocoaaccessibility.h qcocoaaccessibility.mm

qcocoaaccessibilityelement.h qcocoaaccessibilityelement.mm

LIBRARIES

OpenGL::GL # 添加OpenGL库

)

qt_internal_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_sessionmanager

SOURCES

qcocoasessionmanager.cpp qcocoasessionmanager.h

LIBRARIES

OpenGL::GL # 添加OpenGL库

)

Keys ignored in scope 7:.:.:cocoa.pro:TARGET Qt::Widgets:

QT_FOR_CONFIG = "widgets"

Keys ignored in scope 12:.:.:cocoa.pro:NOT TARGET___equals____ss_QT_DEFAULT_QPA_PLUGIN:

PLUGIN_EXTENDS = "-"

/Volumes/MacOS/Program/qt=6.2.0/qtbase/src/opengl/CMakeLists.txt

Generated from opengl.pro.

#####################################################################

OpenGL Module:

#####################################################################

qt_internal_add_module(OpenGL

SOURCES

qopengl2pexvertexarray.cpp qopengl2pexvertexarray_p.h

qopenglbuffer.cpp qopenglbuffer.h

qopenglcustomshaderstage.cpp qopenglcustomshaderstage_p.h

qopengldebug.cpp qopengldebug.h

qopenglengineshadermanager.cpp qopenglengineshadermanager_p.h

qopenglengineshadersource_p.h

qopenglframebufferobject.cpp qopenglframebufferobject.h qopenglframebufferobject_p.h

qopenglgradientcache.cpp qopenglgradientcache_p.h

qopenglpaintdevice.cpp qopenglpaintdevice.h qopenglpaintdevice_p.h

qopenglpaintengine.cpp qopenglpaintengine_p.h

qopenglpixeltransferoptions.cpp qopenglpixeltransferoptions.h

qopenglshadercache_p.h

qopenglshaderprogram.cpp qopenglshaderprogram.h

qopengltexture.cpp qopengltexture.h qopengltexture_p.h

qopengltextureblitter.cpp qopengltextureblitter.h

qopengltexturecache.cpp qopengltexturecache_p.h

qopengltextureglyphcache.cpp qopengltextureglyphcache_p.h

qopengltexturehelper.cpp qopengltexturehelper_p.h

qopengltextureuploader.cpp qopengltextureuploader_p.h

qopenglversionfunctions.cpp qopenglversionfunctions.h qopenglversionfunctions_p.h

qopenglversionfunctionsfactory.cpp qopenglversionfunctionsfactory.h

qopenglversionprofile.cpp qopenglversionprofile.h

qopenglvertexarrayobject.cpp qopenglvertexarrayobject.h

qopenglwindow.cpp qopenglwindow.h

qplatformbackingstoreopenglsupport.cpp qplatformbackingstoreopenglsupport.h

qtopenglglobal.h

DEFINES

QT_NO_FOREACH

QT_NO_USING_NAMESPACE

LIBRARIES

Qt::CorePrivate

Qt::GuiPrivate

PUBLIC_LIBRARIES

Qt::Core

Qt::Gui

PRIVATE_MODULE_INTERFACE

Qt::CorePrivate

Qt::GuiPrivate

)

Scopes:

#####################################################################

qt_internal_extend_target(OpenGL CONDITION QT_FEATURE_opengles2

SOURCES

qopenglfunctions_es2.cpp qopenglfunctions_es2.h

)

qt_internal_extend_target(OpenGL CONDITION NOT QT_FEATURE_opengles2

SOURCES

qopenglfunctions_1_0.cpp qopenglfunctions_1_0.h

qopenglfunctions_1_1.cpp qopenglfunctions_1_1.h

qopenglfunctions_1_2.cpp qopenglfunctions_1_2.h

qopenglfunctions_1_3.cpp qopenglfunctions_1_3.h

qopenglfunctions_1_4.cpp qopenglfunctions_1_4.h

qopenglfunctions_1_5.cpp qopenglfunctions_1_5.h

qopenglfunctions_2_0.cpp qopenglfunctions_2_0.h

qopenglfunctions_2_1.cpp qopenglfunctions_2_1.h

qopenglfunctions_3_0.cpp qopenglfunctions_3_0.h

qopenglfunctions_3_1.cpp qopenglfunctions_3_1.h

qopenglfunctions_3_2_compatibility.cpp qopenglfunctions_3_2_compatibility.h

qopenglfunctions_3_2_core.cpp qopenglfunctions_3_2_core.h

qopenglfunctions_3_3_compatibility.cpp qopenglfunctions_3_3_compatibility.h

qopenglfunctions_3_3_core.cpp qopenglfunctions_3_3_core.h

qopenglfunctions_4_0_compatibility.cpp qopenglfunctions_4_0_compatibility.h

qopenglfunctions_4_0_core.cpp qopenglfunctions_4_0_core.h

qopenglfunctions_4_1_compatibility.cpp qopenglfunctions_4_1_compatibility.h

qopenglfunctions_4_1_core.cpp qopenglfunctions_4_1_core.h

qopenglfunctions_4_2_compatibility.cpp qopenglfunctions_4_2_compatibility.h

qopenglfunctions_4_2_core.cpp qopenglfunctions_4_2_core.h

qopenglfunctions_4_3_compatibility.cpp qopenglfunctions_4_3_compatibility.h

qopenglfunctions_4_3_core.cpp qopenglfunctions_4_3_core.h

qopenglfunctions_4_4_compatibility.cpp qopenglfunctions_4_4_compatibility.h

qopenglfunctions_4_4_core.cpp qopenglfunctions_4_4_core.h

qopenglfunctions_4_5_compatibility.cpp qopenglfunctions_4_5_compatibility.h

qopenglfunctions_4_5_core.cpp qopenglfunctions_4_5_core.h

qopenglqueryhelper_p.h

qopengltimerquery.cpp qopengltimerquery.h

LIBRARIES

OpenGL::GL # 添加 OenGL 库

)

qt_internal_extend_target(OpenGL CONDITION QT_FEATURE_vulkan

SOURCES

qvkconvenience.cpp qvkconvenience_p.h

LIBRARIES

OpenGL::GL # 添加 OenGL 库

)

if(QT_FEATURE_vulkan)

qt_internal_add_target_include_dirs_and_optionally_propagate(

OpenGL WrapVulkanHeaders::WrapVulkanHeaders)

endif()

qt_internal_extend_target(OpenGL CONDITION QT_FEATURE_egl

SOURCES

qopenglcompositor.cpp qopenglcompositor_p.h

qopenglcompositorbackingstore.cpp qopenglcompositorbackingstore_p.h

LIBRARIES

OpenGL::GL # 添加 OenGL 库

)

qt_internal_create_tracepoints(OpenGL qtopengl.tracepoints)

qt_internal_add_docs(OpenGL

doc/qtopengl.qdocconf

)

终端窗口进入/Volumes/MacOS/Program/qt6.2.0/,执行:

cmake ---build . ---parallel

发现报错:

In file included from ../../../3rdparty/chromium/content/public/browser/browser_accessibility_state.h:12:

../../../3rdparty/chromium/content/public/browser/browser_context.h:21:10: fatal error: 'components/spellcheck/spellcheck_buildflags.h' file not found

#include "components/spellcheck/spellcheck_buildflags.h"

文件缺失:qt-6.2.0/qtwebengine/src/3rdparty/chromium/components/spellcheck/spellcheck_buildflags.h

手工创建该文件,写入内容

#define ENABLE_SPELLCHCEK 0

#define BUILDFLAG_INTERNAL_ENABLE_SPELLCHECK 0

修改文件browser_context.h第352行如下

//#if defined(TOOLKIT_QT) && BUILDFLAG(ENABLE_SPELLCHECK)

#if defined(TOOLKIT_QT)

// Inform about not working dictionary for given language

virtual void FailedToLoadDictionary(const std::string& language) = 0;

#endif

最后执行

cmake ---build . ---parallel

cmake --install .

相关推荐
Hua-Jay6 分钟前
OpenCV联合C++/Qt 学习笔记(二十四)----差值法检测移动物体、稠密光流法跟踪移动物体及稀疏光流法跟踪移动物体
c++·笔记·qt·opencv·学习·计算机视觉
boldiy10 分钟前
如何在MAC电脑中实现自动切换windows快捷键
windows·macos
郭老二22 分钟前
【C++】RPC:远程程序调用
c++·rpc
承渊政道22 分钟前
【贪心算法】(经典实战应用解析(六):整数替换、俄罗斯套娃信封问题、可被三整除的最⼤和、距离相等的条形码、重构字符串)
c++·算法·leetcode·贪心算法·排序算法·动态规划·哈希算法
宠..22 分钟前
VS Code SSH 远程连接 Ubuntu 并实现快速运行(C/C++示例)
java·运维·c语言·开发语言·c++·ubuntu·ssh
闻缺陷则喜何志丹30 分钟前
【图论 树 启发式合并】P7165 [COCI2020-2021#1] Papričice|普及+
c++·算法·启发式算法·图论··洛谷
alexwang21132 分钟前
AT_abc458_d [ABC458D] Chalkboard Median题解
c++·算法·题解·atcoder
故事和你9133 分钟前
洛谷-【图论2-4】连通性问题1
开发语言·数据结构·c++·算法·动态规划·图论
我先去打把游戏先40 分钟前
Ubuntu虚拟机(服务器版本)Git安装教程(附常用命令)——从零开始掌握版本控制
服务器·c语言·c++·git·嵌入式硬件·物联网·ubuntu
艾莉丝努力练剑1 小时前
【Linux网络】Linux 网络编程:HTTP(四)从手写服务器到生产级 Nginx 与 cpp-httplib 实战
linux·运维·服务器·网络·c++·nginx·http