解决CMake为VC准备生成文件时的Could not copy from不能复制问题

时间:2022-12-14 20:06:55

今天学习cmake,刚开始学最简单的hello world程序生成例程时,就遇到了问题,cmake显示


E:\AllTestProjects\CmakeProjects\t1>cmake .
-- Building for: Visual Studio 10
-- Check for working C compiler using: Visual Studio 10
Could not copy from: D:/CMake2.8/share/cmake-2.8/Templates/CMakeVSMacros2.vsmacr
os
                 to: d:/我的资料库/Documents/Visual Studio 2010/Projects/VSMacro
s80/CMakeMacros/CMakeVSMacros2.vsmacros

-- Check for working C compiler using: Visual Studio 10 -- works
-- Detecting C compiler ABI info
Could not copy from: D:/CMake2.8/share/cmake-2.8/Templates/CMakeVSMacros2.vsmacr
os
                 to: d:/我的资料库/Documents/Visual Studio 2010/Projects/VSMacro
s80/CMakeMacros/CMakeVSMacros2.vsmacros

-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 10
Could not copy from: D:/CMake2.8/share/cmake-2.8/Templates/CMakeVSMacros2.vsmacr
os
                 to: d:/我的资料库/Documents/Visual Studio 2010/Projects/VSMacro
s80/CMakeMacros/CMakeVSMacros2.vsmacros

-- Check for working CXX compiler using: Visual Studio 10 -- works
-- Detecting CXX compiler ABI info
Could not copy from: D:/CMake2.8/share/cmake-2.8/Templates/CMakeVSMacros2.vsmacr
os
                 to: d:/我的资料库/Documents/Visual Studio 2010/Projects/VSMacro
s80/CMakeMacros/CMakeVSMacros2.vsmacros

-- Detecting CXX compiler ABI info - done
-- This is BINARY dir E:/AllTestProjects/CmakeProjects/t1
-- This is SOURCE dir E:/AllTestProjects/CmakeProjects/t1
-- Configuring done
Could not copy from: D:/CMake2.8/share/cmake-2.8/Templates/CMakeVSMacros2.vsmacr
os
                 to: d:/我的资料库/Documents/Visual Studio 2010/Projects/VSMacro
s80/CMakeMacros/CMakeVSMacros2.vsmacros

CMake Error at CMakeLists.txt:5 (ADD_EXECUTABLE):
  Cannot find source file:

    SRC_LIST

  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
  .hxx .in .txx


-- Build files have been written to: E:/AllTestProjects/CmakeProjects/t1

之所以出现这问题,上网查了,据说是因为,是因为,CMAKE不认中文,不认中文。。。尼玛,不服不行啊。。

网上说的解决办法如下:

以VS2008编译环境为例首先打开VS2008,打开"Tool"菜单->"Option..."->"projects and solutions"选项->"General";然后看看这个"Options"页面右边的"Projects location"; "User project templates location"; "Useritem templates location"这几个文本框下面是否出现包含有中文路径。如果有中文路径,问题的原因也就找到了。如果有中文路径的话,把这几个都改成只包含英文路径,似乎CMake不支持中文,VTK目前是不支持中文。这是因为在用CMake生成VTK.sln工程时,CMake要从vtk的源文件路径里复制一些文件,也就是上面错误所说的"CMakeVSMacros2.vsmacros"等文件到这个目录下,如果这个目录包含有中文,当然就出错了。

在我们安装完VS2008时,一般这几个文本框的路径默认的都会是"D:/我的文档/Visual Studio 2008/Projects"等 ,里面含有中文,然后你再用CMake生成VTK工程时就自然出错了。