CLion新建C++项目无法编译,提示权限拒绝错误
Problem Description
Every time I create a new C++ project in CLion, the console throws a series of permission denied errors during CMake configuration. Old projects work perfectly fine, and uninstalling/reinstalling CLion didn't fix the issue. Here's the full error log:
C:\Users\Diego\.CLion2018.1\system\cygwin_cmake\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=C:/cygwin64/bin/make.exe -DCMAKE_C_COMPILER=C:/cygwin64/bin/gcc.exe -DCMAKE_CXX_COMPILER=C:/cygwin64/bin/c++.exe -G "CodeBlocks - Unix Makefiles" "/cygdrive/c/Users/Diego/Documents/Arquitectura de Computadores/Mini Tareas/Mini Tarea 6/compilador" -- The C compiler identification is unknown -- The CXX compiler identification is unknown -- Check for working C compiler: C:/cygwin64/bin/gcc.exe CMake Error: Cannot open file for write: /cygdrive/c/Users/Diego/Documents/Arquitectura de Computadores/Mini Tareas/Mini Tarea 6/compilador/cmake-build-debug/CMakeFiles/CMakeTmp/CMakeFiles/cmTC_da27f.dir/build.make.tmp CMake Error: : System Error: Permission denied CMake Error: Cannot open file for write: /cygdrive/c/Users/Diego/Documents/Arquitectura de Computadores/Mini Tareas/Mini Tarea 6/compilador/cmake-build-debug/CMakeFiles/CMakeTmp/CMakeFiles/cmTC_da27f.dir/depend.make.tmp CMake Error: : System Error: Permission denied CMake Error: Cannot open file for write: /cygdrive/c/Users/Diego/Documents/Arquitectura de Computadores/Mini Tareas/Mini Tarea 6/compilador/cmake-build-debug/CMakeFiles/CMakeTmp/CMakeFiles/cmTC_da27f.dir/flags.make.tmp CMake Error: : System Error: Permission denied CMake Error: Cannot open file for write: /cygdrive/c/Users/Diego/Documents/Arquitectura de Computadores/Mini Tareas/Mini Tarea 6/compilador/cmake-build-debug/CMakeFiles/CMakeTmp/CMakeFiles/cmTC_da27f.dir/link.txt.tmp CMake Error: : System Error: Permission denied CMake Error: Could not create /cygdrive/c/Users/Diego/Documents/Arquitectura de Computadores/Mini Tareas/Mini Tarea 6/compilador/cmake-build-debug/CMakeFiles/CMakeTmp/CMakeFiles/cmTC_da27f.dir/cmake_clean.cmake CMake Error: Cannot open file for write: /cygdrive/c/Users/Diego/Documents/Arquitectura de Computadores/Mini Tareas/Mini Tarea 6/compilador/cmake-build-debug/CMakeFiles/CMakeTmp/CMakeFiles/cmTC_da27f.dir/DependInfo.cmake.tmp CMake Error: : System Error: Permission denied CMake Error: Cannot open file for write: /cygdrive/c/Users/Diego/Documents/Arquitectura de Computadores/Mini Tareas/Mini Tarea 6/compilador/cmake-build-debug/CMakeFiles/CMakeTmp/CMakeFiles/cmTC_da27f.dir/progress.make.tmp CMake Error: : System Error: Permission denied CMake Error at /cygdrive/c/Users/Diego/.CLion2018.1/system/cygwin_cmake/share/cmake-3.10.3/Modules/CMakeTestCCompiler.cmake:37 (try_compile): Failed to generate test project build system. Call Stack (most recent call first): CMakeLists.txt:2 (project) -- Configuring incomplete, errors occurred! See also "/cygdrive/c/Users/Diego/Documents/Arquitectura de Computadores/Mini Tareas/Mini Tarea 6/compilador/cmake-build-debug/CMakeFiles/CMakeOutput.log". See also "/cygdrive/c/Users/Diego/Documents/Arquitectura de Computadores/Mini Tareas/Mini Tarea 6/compilador/cmake-build-debug/CMakeFiles/CMakeError.log".
Root Cause Analysis
The repeated "Permission denied" messages make it clear that CMake (running via CLion's Cygwin setup) doesn't have write access to the new project's build directory. Old projects work because their directory permissions were already correctly configured, or their paths don't trigger the same permission restrictions. Uninstalling CLion didn't help because the issue is tied to system/directory permissions, not CLion's core installation files.
Solutions to Try
Let's go through actionable steps to fix this:
Check Windows folder permissions for your project directory
Right-click the parent folder of your new project (e.g.,C:\Users\Diego\Documents\Arquitectura de Computadores\Mini Tareas\Mini Tarea 6), select Properties > Security. Ensure your user account (Diego) has Full Control permissions enabled. If not, click Edit to add or modify the permissions, then apply the changes.Run CLion as Administrator
Sometimes, write access to certain directories requires elevated privileges. Right-click the CLion shortcut and select Run as administrator, then try creating a new project again. If this works, you can set CLion to always run as admin by right-clicking the shortcut > Properties > Compatibility > Check "Run this program as an administrator".Verify Cygwin's mount permissions
Since you're using Cygwin's toolchain, open a Cygwin terminal and run themountcommand to check how your C: drive is mounted. Look for a line like/cygdrive/c—if it hasnoaclor read-only restrictions, remount it with write access:mount -o remount,rw /cygdrive/cTo make this permanent, edit the
/etc/fstabfile in your Cygwin installation and ensure the line for/cygdrive/cincludesrwinstead ofro.Clear CLion's residual cache (properly)
Uninstalling CLion might leave behind cached files in your user directory. Manually delete theC:\Users\Diego\.CLion2018.1folder (make sure CLion is closed first), then reinstall CLion. This ensures any corrupted or permission-locked cache files are removed.Change CLion's default build directory
Open CLion's settings (File > Settings > Build, Execution, Deployment > CMake). For the new project, modify the Build directory field to a simpler path (e.g.,../buildinstead of the defaultcmake-build-debug). Sometimes long paths with special characters can trigger permission issues in Cygwin.
内容的提问来源于stack exchange,提问作者D. Vargas

