在WSL:configure_file上对config_file的每次调用都失败:配置文件时出现问题



我刚刚在新的WSL安装(Ubuntu18.04 LTS(上构建并安装了cmake 3.16。然后我创建了一个默认的helloworld项目

(base) ciaran@DESKTOP-K0APGUV:/mnt/d/ATest$ tree .
.
├── CMakeLists.txt
└── main.cpp
//CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(ATest)
set(CMAKE_CXX_STANDARD 14)
add_executable(ATest main.cpp)
//main.cpp
#include <iostream>
#include <string>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}

然后尝试构建:

(base) ciaran@DESKTOP-K0APGUV:/mnt/d/ATest$ mkdir build
(base) ciaran@DESKTOP-K0APGUV:/mnt/d/ATest$ cd build/
(base) ciaran@DESKTOP-K0APGUV:/mnt/d/ATest/build$ cmake ..

我得到了以下内容。

CMake Error at /usr/local/share/cmake-3.16/Modules/CMakeDetermineSystem.cmake:185 (configure_file):
configure_file Problem configuring file
Call Stack (most recent call first):
CMakeLists.txt:2 (project)

-- The C compiler identification is GNU 10.1.0
CMake Error at /usr/local/share/cmake-3.16/Modules/CMakeDetermineCCompiler.cmake:212 (configure_file):
configure_file Problem configuring file
Call Stack (most recent call first):
CMakeLists.txt:2 (project)

-- The CXX compiler identification is GNU 10.1.0
CMake Error at /usr/local/share/cmake-3.16/Modules/CMakeDetermineCXXCompiler.cmake:210 (configure_file):
configure_file Problem configuring file
Call Stack (most recent call first):
CMakeLists.txt:2 (project)

-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Detecting C compile features
-- Detecting C compile features - done
CMake Error at /usr/local/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:80 (configure_file):
configure_file Problem configuring file
Call Stack (most recent call first):
CMakeLists.txt:2 (project)

-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /usr/local/share/cmake-3.16/Modules/CMakeTestCXXCompiler.cmake:73 (configure_file):
configure_file Problem configuring file
Call Stack (most recent call first):
CMakeLists.txt:2 (project)

-- Configuring incomplete, errors occurred!
See also "/mnt/d/ATest/build/CMakeFiles/CMakeOutput.log".
See also "/mnt/d/ATest/build/CMakeFiles/CMakeError.log".
(base) ciaran@DESKTOP-K0APGUV:/mnt/d/ATest/build$

我最初尝试过cmake 3.15,但升级后想看看它是否是版本问题,考虑到这一点,我不认为是。我也尝试过g++-7g++-9,它们的行为相同。

有人知道这里可能发生了什么吗?谢谢

  1. 使用以下文本在/etc/中创建一个名为wsl.conf的文件:
# /etc/wsl.conf
[automount]
options = "metadata"
enabled = true
  1. 重新启动wsl:

wsl.exe -t Ubuntu // (or other e.g. Debian)

来源:

  • https://intellij-support.jetbrains.com/hc/en-us/community/posts/360003413779-Troubles-with-WSL-toolchain-Test-CMake-run-finished-with-errors-
  • https://github.com/microsoft/WSL/issues/3994#issuecomment-507864837
  • https://learn.microsoft.com/en-us/windows/wsl/wsl-config

我能够通过按顺序运行以下命令来修复上述错误:

% cd build
% cmake -B . -S ..
% cmake --build .

此解决方案取自此处。

相关内容

最新更新