远程系统没有CMake 3.8或更高版本

jrcvhitl  于 2023-05-22  发布在  其他
关注(0)|答案(3)|浏览(337)

1.问题介绍
我正在尝试创建一个MacOS应用程序,使用Windows上的Visual Studio 2022(最新版本17.2.0)和CMake模板在C++中打印“Hello World”,以便我可以远程连接(使用SSH)到MacOS,我一直在关注this official Microsoft tutorial
1.出现问题
问题是,当我在MacOS中进行CMake的安装步骤时,我无法让它识别安装的MacOS版本,因为当我在Windows中打开项目时,我在控制台中收到以下消息:

1> Copying files to the remote machine.
1> Starting copying files to remote machine.
1> Finished copying files (elapsed time 00h:00m:00s:650ms).
1> CMake generation started for configuration: 'macos-debug'.
1> Found cmake executable at /Users/maria/.vs/cmake/bin/cmake.
1> The remote system does not have CMake 3.8 or greater. An infobar to automatically deploy CMake to the remote system will be displayed if you are building on a supported architecture. See https://aka.ms/linuxcmakeconfig for more info.

它还显示上面的以下消息:

Supported CMake version is not present on 'remote address'. Install  latest CMake binaries from CMake.org? Yes No

当我按“是”时,它说我实际上在远程MacOS上安装了cmake:

1> Copying files to the remote machine.
1> Starting copying files to remote machine.
1> Finished copying files (elapsed time 00h:00m:00s:650ms).
1> CMake generation started for configuration: 'macos-debug'.
1> Found cmake executable at /Users/maria/.vs/cmake/bin/cmake.
1> The remote system does not have CMake 3.8 or greater. An infobar to automatically deploy CMake to the remote system will be displayed if you are building on a supported architecture. See https://aka.ms/linuxcmakeconfig for more info.
CMake binary deployment to the remote machine started. CMake generation will continue automatically after deployment finishes.

CMake binary deployment to the remote machine failed: Installation directory '/Users/maria/.vs/cmake' already exists.

1.解决方案尝试
我尝试使用brew(最新版本3.23.1)安装CMake,并确保可以直接从MacOS终端(包含在PATH中)访问cmake,我还尝试通过将“CMake.app”复制到“/Applications”并使用以下命令将其添加到路径来安装image .dmg,从而执行the official guide之后的过程:
export PATH=/Applications/CMake.app/Contents/bin:$PATH
我甚至尝试安装旧版本的CMake(如3.8.0或3.8.1),但同样的事情仍然发生。预期结果与此处显示的Microsoft指南相同:

1> Copying files to the remote machine.
1> Starting copying files to remote machine.
1> Finished copying files (elapsed time 00h:00m:00s:650ms).
1> CMake generation started for configuration: 'macos-debug'.
1> Found cmake executable at /Applications/CMake.app/Contents/bin/cmake.
1> /Applications/CMake.app/Contents/bin/cmake -G "Ninja"  DCMAKE_BUILD_TYPE_STRING="Debug" -DCMAKE_INSTALL_PREFIX
1> [CMake] -- Configuring done
1> [CMake] -- Generating done
1> [CMake] -- Build files have been written to: /Users/cti/.vs/CMakeProject90/out/build/macos-debug
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted code model.
1> Extracted includes paths.
1> CMake generation finished.

有谁知道为什么会发生这种情况,或者有什么办法可以解决这个问题?

r8xiu3jd

r8xiu3jd1#

这似乎是Visual Studio的一个bug。你可以跟踪它here

解决方案

看起来Visual Studio总是在当前通过SSH连接的用户的本地文件夹下查找CMake(即~/.vs/cmake/bin/cmake),不管你是如何安装的。然后,当Visual Studio建议安装它时:
“192.168.1.180”上不存在支持的CMake版本。从www.example.com安装最新的CMake二进制文件CMake.org?
如果你同意这样做,它实际上推出它在本地的文件夹。Visual Studio使用的二进制文件已损坏,如果您尝试在Mac计算机上本地使用它,则会引发错误:

$: ~/.vs/cmake/bin/cmake
zsh: exec format error: /Users/User/.vs/cmake/bin/cmake

这就是为什么Visual Studio一直在努力寻找工作的CMake二进制文件。您可以通过创建一个符号链接到包含工作CMake二进制文件的文件夹来代替Visual Studio在其中查找它们的文件夹:

$: rm -rf ~/.vs/cmake/bin
$: ln -s /Applications/CMake.app/Contents/bin ~/.vs/cmake/bin

此时,Visual Studio将能够定位CMake,但无法定位默认编译器和生成器:

1> /Users/User/.vs/cmake/bin/cmake -G "Ninja"   -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="/Users/User/.vs/CrossPlatform/out/install/macos-debug"  /Users/User/.vs/CrossPlatform/CMakeLists.txt;
1> [CMake] CMake Error: CMake was unable to find a build program corresponding to "Ninja".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
1> [CMake] CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
1> [CMake] CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage

解决这个问题的最简单方法就是在Mac机器上运行这个命令。它将生成Visual Studio可以使用该高速缓存,但是请注意,无论何时此缓存因任何原因而无效(例如在配置之间切换时),您必须以相同的方式重新生成它。另一种选择是显式指定所有缺少的参数(通过CMakeLists.txt或作为CMakePresets.jsoncacheVariables属性下的命令行参数)

5kgi1eie

5kgi1eie2#

我终于解决了这个问题,我不得不复制位于CMake应用程序中的文件:/Applications/CMake.app/Contents/bin/cmake到Visual Studio试图找到它们的位置,在我的例子中是:/Users/maria/.vs/cmake/bin/cmake
这个版本不是问题,因为我用最新的CMake版本(3. 23. 1)试过了,效果很好。最后,我发现了一个问题,与C++和C for CMake的编译器的位置以及Ninja的位置缺乏指示有关,我只是在CMakePresets.json中指定了它,我没有遇到大问题:

{
        "name": "macos-debug",
        "displayName": "macOS Debug",
        "generator": "Ninja",
        "binaryDir": "${sourceDir}/out/build/${presetName}",
        "installDir": "${sourceDir}/out/install/${presetName}",
        "cacheVariables": {
          "CMAKE_BUILD_TYPE": "Debug",
          "CMAKE_C_COMPILER": "/usr/bin/gcc",
          "CMAKE_CXX_COMPILER": "/usr/bin/g++",
          "CMAKE_MAKE_PROGRAM": "/usr/local/bin/ninja"
        },
        "condition": {
            "type": "equals",
            "lhs": "${hostSystemName}",
            "rhs": "Darwin"
        },
        "vendor": {
            "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
                "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
            }
        }
    }

我希望有人会发现这是一个有用的解决方案时,在MacOS上开发与Visual Studio(在Windows上)

7rtdyuoh

7rtdyuoh3#

我认为这是Visual Studio的一个bug。在Visual Studio中打开Tool菜单,然后打开Options-Cross-Platform-Logging and Diagnostics,选中Startup Logging and Log进入输出窗口中的跨平台日志空间。
Here is a screenshot
然后重新生成,切换到跨平台日志记录,您将看到visual studio如何查找cmake。使用realpath -m -L cmakereadlink -f -m cmake命令。此命令的参数可以在Linux上工作,但在macOS上是错误的。另外,which cmake命令直接在macOS终端中运行也是正确的,但是Visual Studio得到了一个错误的值1,我认为这是Visual Studio的一个bug。

11:06:26.3008967 [Info, Thread 72]  liblinux.RemoteSystemBase: Connecting over SSH to 172.16.166.87:22
11:06:26.8752198 [Info, Thread 85]  liblinux.IO.RemoteFileSystemImpl: Connecting over SFTP to 172.16.166.87:22
11:06:27.3023959 [Info, Thread 85]  liblinux.Shell.CommonCommandBase: Command "realpath -m -L /Users/sobey/.vs/CMakeProject2" finished with exit code 1 after 11.4896ms
11:06:27.3147959 [Info, Thread 85]  liblinux.Shell.CommonCommandBase: Command "readlink -f -m /Users/sobey/.vs/CMakeProject2" finished with exit code 1 after 12.3538ms
11:06:27.3232282 [Info, Thread 85]  liblinux.Shell.CommonCommandBase: Command "echo /Users/sobey/.vs/CMakeProject2" finished with exit code 0 after 8.7827ms
11:06:27.3386039 [Info, Thread 85]  liblinux.Shell.CommonCommandBase: Command "realpath -m -L /Users/sobey/.vs/CMakeProject2" finished with exit code 1 after 11.1806ms
11:06:27.3485238 [Info, Thread 85]  liblinux.Shell.CommonCommandBase: Command "readlink -f -m /Users/sobey/.vs/CMakeProject2" finished with exit code 1 after 10.2662ms
11:06:27.3569562 [Info, Thread 85]  liblinux.Shell.CommonCommandBase: Command "echo /Users/sobey/.vs/CMakeProject2" finished with exit code 0 after 8.3939ms
11:06:27.3594358 [Info, Thread 85]  liblinux.RemoteSystemBase: Disconnecting over SSH from "172.16.166.87:22"
11:06:27.3594358 [Info, Thread 85]  liblinux.IO.RemoteFileSystemImpl: Disconnecting over SFTP from 172.16.166.87:22
11:06:27.3703480 [Info, Thread 56]  liblinux.RemoteSystemBase: Connecting over SSH to 172.16.166.87:22
11:06:27.7060812 [Info, Thread 85]  liblinux.IO.RemoteFileSystemImpl: Connecting over SFTP to 172.16.166.87:22
11:06:28.1425157 [Info, Thread 85]  liblinux.Shell.CommonCommandBase: Command "realpath -m -L /Users/sobey/.vs/CMakeProject2/out/build/macos-debug" finished with exit code 1 after 10.7206ms
11:06:28.1528399 [Info, Thread 85]  liblinux.Shell.CommonCommandBase: Command "readlink -f -m /Users/sobey/.vs/CMakeProject2/out/build/macos-debug" finished with exit code 1 after 10.239ms
11:06:28.1612972 [Info, Thread 85]  liblinux.Shell.CommonCommandBase: Command "echo /Users/sobey/.vs/CMakeProject2/out/build/macos-debug" finished with exit code 0 after 8.1892ms
11:06:28.1712170 [Info, Thread 85]  liblinux.Shell.CommonCommandBase: Command "realpath -m -L /Users/sobey/.vs/CMakeProject2" finished with exit code 1 after 10.1788ms
11:06:28.1821286 [Info, Thread 85]  liblinux.Shell.CommonCommandBase: Command "readlink -f -m /Users/sobey/.vs/CMakeProject2" finished with exit code 1 after 10.5324ms
11:06:28.1900667 [Info, Thread 85]  liblinux.Shell.CommonCommandBase: Command "echo /Users/sobey/.vs/CMakeProject2" finished with exit code 0 after 8.1115ms
11:06:28.1999858 [Info, Thread 85]  liblinux.Shell.CommonCommandBase: Command "realpath -m -L cmake" finished with exit code 1 after 9.6801ms
11:06:28.2099052 [Info, Thread 85]  liblinux.Shell.CommonCommandBase: Command "readlink -f -m cmake" finished with exit code 1 after 9.7734ms
11:06:28.2183364 [Info, Thread 85]  liblinux.Shell.CommonCommandBase: Command "echo cmake" finished with exit code 0 after 8.357ms
11:06:28.2282572 [Info, Thread 85]  liblinux.Shell.CommonCommandBase: Command "which cmake" finished with exit code 1 after 8.9331ms
11:06:28.2381776 [Info, Thread 85]  liblinux.Shell.CommonCommandBase: Command "realpath -m -L $HOME/.vs/cmake/bin/cmake" finished with exit code 1 after 10.0032ms
11:06:28.2485936 [Info, Thread 85]  liblinux.Shell.CommonCommandBase: Command "readlink -f -m $HOME/.vs/cmake/bin/cmake" finished with exit code 1 after 10.105ms
11:06:28.2565294 [Info, Thread 85]  liblinux.Shell.CommonCommandBase: Command "echo $HOME/.vs/cmake/bin/cmake" finished with exit code 0 after 8.1526ms
11:06:28.2590084 [Info, Thread 76]  liblinux.RemoteSystemBase: Disconnecting over SSH from "172.16.166.87:22"
11:06:28.2595046 [Info, Thread 76]  liblinux.IO.RemoteFileSystemImpl: Disconnecting over SFTP from 172.16.166.87:22

Log screenshot
Terminal execution command screenshot

相关问题