Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mac+vscode+qt安装配置手册 #1

Open
Seasons123 opened this issue Apr 15, 2022 · 2 comments
Open

mac+vscode+qt安装配置手册 #1

Seasons123 opened this issue Apr 15, 2022 · 2 comments

Comments

@Seasons123
Copy link
Owner

Seasons123 commented Apr 15, 2022

前言:

首先对Visual Studio Code做一个大概的介绍。首先明确一下,这个Visual Studio Code(以下简称vscode)是一个带GUI的代码编辑器,也就是只能完成简单的代码编辑功能,并不是一个集成开发环境(IDE)。而Visual Studio、WebStorm这类的开发工具是IDE,功能强大,这两个是不一样的概念。对比VS Code和传统Visual Studio,二者间最大的不同是:VS Code专注于成为一个全功能编辑器,而VS则围绕项目本身提供了许多相关功能。VS Code没有新项目向导,也不支持solution文件。但是它确实提供了响应式编辑功能,强化了很多小细节,例如:当你处理跨平台文件时显示行结束符类型。

xcode+qt也可以配置成功进行qt的开发,因为vscode就是个编辑器,编译的部分还是要xcode完成,mac平台xcode是第一选择。不过如果不是做 iOS iPad 或者 mac 相关的开发,个人更倾向于选择vscode,因为vscode跨平台,插件多,性能和体验(尤其是调试功能)个人感觉都更好一些。:watermelon:

一.配置环境:

Macbook Pro操作系统MacOS Monterey 12.1,Xcode版本是13.3,如果操
作系统是MacOS Catalina 10.15.4,Xcode版本需要安装10.3,Xcode版本需要和自己的操作系统版本匹配。

1、Xcode各版本下载网址:https://developer.apple.com/download/all/?q=Xcode
2、彻底卸载xcode方法:
(1)注意:卸载xode时,根目录下的必须要用到管理员权限。
sudo rm -rf /Applications/Xcode.app
sudo rm -rf /Library/Preferences/com.apple.dt.Xcode.plist
(2)然后删除自己目录下的
rm -rf ~/Library/Preferences/com.apple.dt.Xcode.plist
rm -rf ~/Library/Caches/com.apple.dt.Xcode
rm -rf ~/Library/Application\ Support/Xcode
(3)以及和开发者相关的
rm -rf ~/Library/Developer/Xcode
rm -rf ~/Library/Developer/CoreSimulator
rm -rf ~/Library/Developer/XCPGDevices
(4)xcode缓存目录
sudo rm -rf ~/Library/Developer/Xcode/DerivedData

二.安装qt5.12.12

下载网址:https://mirrors.cloud.tencent.com/qt/official_releases/qt/5.12/5.12.12/

三.qmake转cmake

1、参考教程:

https://www.yuque.com/pikachuhy/cmake/cil1pi
https://blog.csdn.net/u014779536/article/details/109163452
http://t.zoukankan.com/ohsolong-p-10825573.html

2、下面是根据源程序的.pro文件转换编写的CMakeLists.txt文件内容:

cmake_minimum_required(VERSION 3.23  FATAL_ERROR)
project(rwcapviewer)
set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_PREFIX_PATH "/Users/peichunyan/Qt/5.12.12/clang_64")
add_compile_options(-std=c++11)
set(TARGET rwcapviewer)
set(CMAKE_AUTOMOC ON)


set(HEADERS Viewer3D.h Cap3d.h Utils.h Vertex3D.h Matrix3x3.h MainWindow.h Viewer2DTop.h Viewer2DXoz.h Geo3D.h Geo3DPlane.h Geo3DPlaneTop.h Geo3DPlaneXoz.h Geo3DZBuffer.h  ControlPanel.h Geo3DPlaneYoz.h Viewer2DYoz.h clipper.hpp Cap3dCompare.h GdsWriter.h GdsFormat.h)

set(SOURCES main.cpp Viewer3D.cpp Cap3d.cpp Utils.cpp Matrix3x3.cpp MainWindow.cpp Viewer2DTop.cpp Viewer2DXoz.cpp Geo3D.cpp Geo3DPlane.cpp  Geo3DPlaneTop.cpp Geo3DPlaneXoz.cpp  Geo3DZBuffer.cpp  ControlPanel.cpp   Geo3DPlaneYoz.cpp  Viewer2DYoz.cpp  clipper.cpp   Cap3dCompare.cpp  GdsWriter.cpp)

set(RESOURCES ../icons/icons.qrc)
# set(FORMS widget.ui)
# set(QT Core Gui Widgets)


# 为每个模块提供*.cmake文件搜索路径
set(Qt5_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5")
set(Qt5Widgets_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5Widgets")
set(Qt5Network_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5Network")
set(Qt5LinguistTools_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5LinguistTools")
set(Qt5QApplication_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5QApplication")
set(Qt5QtWidgets_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5QtWidgets")

    
find_package(Qt5 COMPONENTS Widgets Network LinguistTools)

qt5_add_resources(RESOURCES_RCC ${RESOURCES})

add_executable(${TARGET} ${HEADERS} ${SOURCES} ${RESOURCES_RCC})

target_link_libraries(${TARGET}
        Qt5::Core
        Qt5::Gui
        Qt5::Widgets
)

【备注】:CMAKE_PREFIX_PATH的配置地址替换为自己Qt本地安装的地址

四.vscode部分

1、下载并安装vscode
2、安装插件C\C++,C\C++ Clang Command Adapter,CodeLLDB(用来debug),CMake,CMake Tools,Qt Configure,Qt Tools。
image
image
image
image
image

3、 添加配置文件:c_cpp_properties.json、tasks.json、launch.json、setting.json。
(1) shift+command+P点击C/C++ 编辑配置(JSON),出现文件c_cpp_properties.json,将文件的配置内容修改如下:

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/Applications/Xcode.app/Contents/Developer/Platforms/**",
                "/Users/peichunyan/Qt/5.12.12/clang_64/include/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "intelliSenseMode": "clang-x64",
            "compileCommands": "${workspaceFolder}/build/compile_commands.json"
        }
    ],
    "version": 4
}

【备注】:includePath的配置地址替换为本地地址

(2) shift+command+B一直点击直到other,如下配置tasks.json文件。将文件的配置内容修改如下:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "clang++ build active file",
      "type": "shell",
      "command": "clang++",
      "args": [        
        "${file}",
        "-lstdc++", 
        "-std=c++11",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}",
        "-g",
        "--debug"
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      }
    }
  ]
}

(3) launch.json配置如下:

{
  "version": "0.2.0",
  "configurations": [
    {
        "name": "clang++ - Build and debug active file",
        "type": "lldb",
        "request": "launch",
        "program": "${workspaceFolder}/build/rwcapviewer",
        "args": [],
        "cwd": "${workspaceFolder}"
    }
]
}

【备注】:program的配置地址替换为本地地址

(4) settings.json配置如下:

{
    "cmake.sourceDirectory": "${workspaceFolder}/src",
    "C_Cpp_Runner.cppStandard": "c++11",
    "files.associations": {
        "Makefile": "cmake",
        "qtwidgets": "qt",
        "qapplication": "qt",
        "iostream": "cpp"
    }
}

【备注】:cmake.sourceDirectory的配置地址替换为本地地址

4、点击下图箭头处,即可调试程序。另外,其它qt的开发和调试功能也都稳定支持。
image

@Seasons123
Copy link
Owner Author

Seasons123 commented Apr 20, 2022

【附】关于qt creator调试的坑总结:
1、一点调试就出来两个这个信息就结束了。这种情况打断点也没用的,所有的都正常,只是在需要弹出界面时直接退出,这种问题非常的难查
image
解答:这种情况一般是内存异常导致的,但这种异常,QT调试器根本就不报错误。说白了就是程序有bug,导致程序崩溃了,但是调试器却根本就不报bug,全部按正常来处理,然后在弹界面时直接退出(因为崩溃了)。解决这种问题的办法之一可以对新增的代码一行行的排查,或者改用vs code调试
2、这种情况也是,打断点没用,只报一个意外退出的错误。解决方法同上。
image

@Seasons123
Copy link
Owner Author

调研思考了一下关于qt开发环境的选择:为避免出现处理奇怪问题消耗不必要的时间,优先使用在服务器上的qt creator运行调试开发;本地的话使用和公司一致的开发环境qt creator5.9(公司Linux上版本是5.9.2,Windows上版本是5.9.11),如果再出现莫名其妙的意外退出错误,再使用vscode作为临时过渡开发

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant