如何在Visual Studio 2019中编译Putty 0.78?遇CMake错误求助
PuTTY 0.78 Windows编译CMake错误解决指南
问题场景
编译Windows版PuTTY 0.78时,发现源码里没有Makefile.vc或Visual Studio项目文件。尝试在Visual Studio 2019中直接打开windows子目录,触发如下CMake错误:
Severity Code Description Project File Line Suppression State
Error CMake Error at C:\Users\user\Downloads\Compressed\putty-src\windows\CMakeLists.txt:3 (add_sources_from_current_dir):
Unknown CMake command "add_sources_from_current_dir". C:\Users\user\Downloads\Compressed\putty-src\windows\CMakeLists.txt 3
解决步骤
- 从源码根目录启动CMake:PuTTY的自定义CMake函数(比如
add_sources_from_current_dir)定义在根目录的CMake配置文件中,直接打开putty-src根目录(而非windows子目录)让VS自动加载完整的CMake配置,就能识别该函数。 - 确认CMake版本达标:PuTTY 0.78要求CMake 3.14或更高版本,执行
cmake --version检查版本,低于要求则更新CMake。 - 命令行编译备选方案:若VS图形界面配置失败,在
putty-src根目录执行以下命令生成VS工程文件:
(需要64位版本就把cmake -S . -B build -G "Visual Studio 16 2019" -A Win32-A Win32改成-A x64)生成后打开build/PuTTY.sln即可正常编译,编译产物会输出到build/windows目录下。
内容的提问来源于stack exchange,提问作者dorita borita
相关产品推荐
相关产品推荐

