加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Zlib
cd build
cmake -G"Unix Makefiles" ../
很不幸,这一步会出问题
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "D:/tmp/build/CMakeFiles/CMakeOutput.log".

解决方法就是找到mingw安装目录下mingw32-make.exe拷贝一份并重命名为make.exe

再运行cmake -G "Unix Makefiles" ../   cmake -G "MinGW Makefiles" ../   
或者使用
cmake -G "Visual Studio 16 2019" ..
<path_to_source> 是要编译的项目路径

//不改不行,测试了失败
其实也可以不改名字,-G“MinGW Makefiles" 可以直接用mingw32-make
需要在MinGW安装路径下进行操作,本来只有mingw32-make.exe文件,你需要复制一份改名为make.exe

Note
在使用了Qt宏的文件 都会被moc编译生成 在cpp文件下最后面必须包含 #include "filename.moc"  不然会报错  undefined reference to `vtable for MyWidget'

配置CMAKE Qt6的环境很麻烦
先安装C/C++的插件 
在安装cmake  cmake highlight  cmake toole(重要)  git相关  qt tools qt configure qml

ctrl shift p 设置mingw路径 g++ gcc  等等,windows和linux都要配置Qt的路径

c_cpp_properties.json中需要包含Qt的头文件路径,不然找不到头文件,无法跳转

一些使用命令
cd build & cmake -Bbuild -DCMAKE_MAKE_PROGRAM=D:/mingw64/bin/make.exe -G "MinGW Makefiles" ../

设置Mingw Debug调试的方法
1.需要将exe所需要的动态库文件放在exe目录,还有关于Qt的platforms或者其他依赖的内容
2.修改tasks.json、launch.json、setting.json等配置文件的内容为自己本地电脑的设置

使用vs的Developer Command promot for vs2022
windows下查看库是32还是64
dumpbin.exe   /headers   文件

查看库是静态库还是动态库
lib /list [文件名] 显示dll的是导入库,显示.obj或者.o是静态库

查看DLL库文件信息(包含的符号)
dumpbin –exports export_dlld.dll

查看lib库文件信息(包含的函数)
dumpbin /exports mysqlcppconn-static.lib



在visual studio中添加mingw编译器的方法
https://blog.csdn.net/witton/article/details/126211289

1.新建的项目,默认是生成的“CMakePresets.json”预设文件,先将之删除掉或者在VS选项中设置CMake为“从不使用CMakePresets.json”,然后在项目中选择“test的CMake设置”,此时项目中会创建一个CMakeSettings.json的文件;这里的test指的是你的,也可以是CCC的CMake设置
2.双击即可打开CMake的设置编辑器,删除默认的x64-Debug,然后点击添加就会出现mingw-Release  mingw-Debug;
3.将CMAKE-C-COMPLIER	中的${env.BIN_ROOT}/ gcc.exe删除改为gcc,g++同理;intelliSenseMode为"linux-gcc-x64":

4.在“解决方案资源管理器”中的CMakeLists.txt文件上右键,在弹出的菜单中选择“添加调试配置;然后在弹出的“选择调试程序”对话框中选择“MinGW/Cygin(gdb)的C/C++启动”
5.会创建一个launch.vs.json文件
{
  "version": "0.2.1",
  "defaults": {},
  "configurations": [
    {
      "type": "default",
      "project": "CMakeLists.txt",
      "projectTarget": "CurveIVTest.exe (C:\\DevelopWork\\CurveIVTest\\bin\\CurveIVTest.exe)",
      "name": "CurveIVTest.exe (C:\\DevelopWork\\CurveIVTest\\bin\\CurveIVTest.exe)",
      "args": [
        "-qmljsdebugger=file:{f8440d51-07ce-4b34-8880-be70c601f284},block"
      ]
    },
    {
      "type": "default",
      "project": "CMakeLists.txt",
      "projectTarget": "CurveIVTest.exe (C:\\DevelopWork\\CurveIVTest\\bin\\CurveIVTest.exe)",
      "name": "QML Application",
      "args": [
        "-qmljsdebugger=file:{e1a7f0bd-46f3-43e6-8715-4ba2263d17dd},block"
      ]
    },
    {
      "type": "cppdbg",
      "name": "CMakeLists.txt",
      "project": "CMakeLists.txt",
      "projectTarget": "",
      "cwd": "${workspaceRoot}",
      "program": "C:\\DevelopWork\\CurveIVTest\\bin\\CurveIVTest.exe",
      "MIMode": "gdb",
      "miDebuggerPath": "C:\\DevelopSoftware\\Qt6\\Tools\\mingw1120_64\\bin\\gdb.exe",
      "externalConsole": true,
      "setupCommands": [
        {
          "description": "为 gdb 启用整齐打印",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        },
        {
          "description": "将反汇编风格设置为 Intel",
          "text": "-gdb-set disassembly-flavor intel",
          "ignoreFailures": true
        }
      ]
    }
  ]
}


6.把调试目标设置为“CMakeLists.txt”,F5就可以调试了

7.vs2022有个默认配置,需要在cmakelists.txt中的project上面添加

if(DEFINED ENV{CFLAGS})
message(STATUS $ENV{CFLAGS})
unset(ENV{CFLAGS})
endif()
if(DEFINED ENV{CXXFLAGS})
message(STATUS $ENV{CXXFLAGS})
unset(ENV{CXXFLAGS})
endif()
zlib License (C) 2024 smallStonela This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution.

简介

测试使用Cmake构建Qt6.0+的项目 展开 收起
Zlib
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化