CMake必须运行两次,第一次总是失败



我在win10 WSL上运行cmake与ubuntu20.04, apt-get安装cmake并使用最简单的CMakeLists.txt如下:

cmake_minimum_required(VERSION 3.4)
project(my)
add_executable(testConst01 testConst.c01)

运行mkdir build; cd build; cmake ../my,它会给出一堆错误:

CMake Error at /usr/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 9.4.0
CMake Error at /usr/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 9.4.0
CMake Error at /usr/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/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/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/my/build/CMakeFiles/CMakeOutput.log".
See also "/mnt/d/my/build/CMakeFiles/CMakeError.log".

然后我第二次运行cmake,一切正常,make命令将生成我想要的所有内容。然后将rm -fr放入build目录,重新执行此操作。第一次失败,第二次成功。总是这样。

我看了看CMakeOutput.log和CMakeError.log文件,也没有发现任何真正的错误信息。

这个问题的原因是什么,如何解决?谢谢!

最后我发现这是WSL配置问题,而不是cmake问题,如本线程所述:

每次调用configure_file在WSL上失败:configure_file配置文件问题

修复步骤:在wsl命令行窗口中,sudo vi /etc/wsl.conf添加以下行:

options = "metadata"
enabled = true

然后关闭所有的wsl窗口

然后在cmd.exe或powershell中,重新启动我的linux实例。例:我正在使用Ubuntu20.04wsl -t Ubuntu20.04

然后运行我的cmake作业,现在一切正常。

相关内容

  • 没有找到相关文章

最新更新