Visual Studio-CMake-Mingw64配置

问题描述

我正在使用Visual Studio 2019创建跨平台的C ++ CMake HelloWorld项目。

我已使用Visual Studio 2019 具有C ++工具集的Linux开发创建了项目,并创建了一个CMake Project

该项目可以在Linux-GCC-Debug中编译并正常运行,但是在创建Minigw64配置时遇到了问题。

我已按照此处的说明安装了MSYS2:https://www.msys2.org/

我已经通过安装devel软件包设置了MinGW环境。

pacman -S make gettext base-devel
pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-x86_64-ninja 
pacman -S mingw-w64-x86_64-gdb

当我尝试生成CMake缓存时,出现以下错误

Determining if the C compiler works Failed with the following output:
Change Dir: C:/Users/lawsm/source/repos/HelloCmake/out/build/Mingw64-Debug/CMakeFiles/CMakeTmp

Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_4b37c && [1/2] Building C object CMakeFiles/cmTC_4b37c.dir/testCCompiler.c.obj

[2/2] Linking C executable cmTC_4b37c.exe

Failed: cmTC_4b37c.exe 

cmd.exe /C "cd . && C:\msys64\mingw64\bin\gcc.exe    CMakeFiles/cmTC_4b37c.dir/testCCompiler.c.obj  -o cmTC_4b37c.exe -Wl,--out-implib,libcmTC_4b37c.dll.a -Wl,--major-image-version,--minor-image-version,0  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."

collect2.exe: error: ld returned 5 exit status
ninja: build stopped: subcommand Failed.

我的CMakeSettings.json是这样的:

{
  "configurations": [
    {
      "name": "Mingw64-Debug","generator": "Ninja","configurationType": "Debug","buildroot": "${projectDir}\\out\\build\\${name}","installroot": "${projectDir\\out\\install\\${name}","cmakeCommandArgs": "","buildCommandArgs": "-v","ctestCommandArgs": "","inheritEnvironments": [ "mingw_64" ],"environments": [
        {
          "MINGW64_ROOT": "C:\\msys64\\mingw64","BIN_ROOT": "${env.MINGW64_ROOT}\\bin","FLAVOR": "x86_64-w64-mingw32","TOOLSET_VERSION": "7.3.0","PATH": "${env.MINGW64_ROOT}\\bin;${env.MINGW64_ROOT}\\..\\usr\\local\\bin;${env.MINGW64_ROOT}\\..\\usr\\bin;${env.MINGW64_ROOT}\\..\\bin;${env.PATH}","INCLUDE": "${env.INCLUDE};${env.MINGW64_ROOT}\\include\\c++\\${env.TOOLSET_VERSION};${env.MINGW64_ROOT}\\include\\c++\\${env.TOOLSET_VERSION}\\tr1;${env.MINGW64_ROOT}\\include\\c++\\${env.TOOLSET_VERSION}\\${env.FLAVOR}","environment": "mingw_64"
        }
      ],"variables": [
        {
          "name": "CMAKE_C_COMPILER","value": "${env.BIN_ROOT}\\gcc.exe","type": "STRING"
        },{
          "name": "CMAKE_CXX_COMPILER","value": "${env.BIN_ROOT}\\g++.exe","type": "STRING"
        }
      ],"intelliSenseMode": "linux-gcc-x64","cmaketoolchain": ""
    }
  ]
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)