Search code examples
cmakeclion

CMake path with special symbols


I'm using CLion and whenever I'm working on a project, it can't be in path with special symbols (such as º, ç, ã...), failing with the following message:

The C compiler

    "C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gcc.exe"

  is not able to compile a simple test program.

Solution

  • MinGW's make program does not handle non-ASCII characters smoothly. I was able to reproduce this on my machine using a path containing ñ:

      The C compiler
    
        "C:/apps/MinGW/bin/gcc.exe"
    
      is not able to compile a simple test program.
    
      It fails with the following output:
    
        Change Dir: C:/workspace/peña/build2/CMakeFiles/CMakeTmp
    
        Run Build Command(s):C:/apps/MinGW/bin/mingw32-make.exe cmTC_fe654/fast && C:/apps/MinGW/bin/mingw32-make.exe -f CMakeFiles\cmTC_fe654.dir\build.make CMakeFiles/cmTC_fe654.dir/build
        mingw32-make.exe[1]: Entering directory 'C:/workspace/pe±a/build2/CMakeFiles/CMakeTmp'
        Building C object CMakeFiles/cmTC_fe654.dir/testCCompiler.c.obj
        C:\apps\MinGW\bin\gcc.exe    -o CMakeFiles\cmTC_fe654.dir\testCCompiler.c.obj   -c C:\workspace\pe├▒a\build2\CMakeFiles\CMakeTmp\testCCompiler.c
        gcc.exe: error: C:\workspace\pe├▒a\build2\CMakeFiles\CMakeTmp\testCCompiler.c: No such file or directory
        gcc.exe: fatal error: no input files
        compilation terminated.
        CMakeFiles\cmTC_fe654.dir\build.make:81: recipe for target 'CMakeFiles/cmTC_fe654.dir/testCCompiler.c.obj' failed
        mingw32-make.exe[1]: *** [CMakeFiles/cmTC_fe654.dir/testCCompiler.c.obj] Error 1
        mingw32-make.exe[1]: Leaving directory 'C:/workspace/pe±a/build2/CMakeFiles/CMakeTmp'
        Makefile:137: recipe for target 'cmTC_fe654/fast' failed
        mingw32-make.exe: *** [cmTC_fe654/fast] Error 2
    

    Note, CMake switches to the temporary build directory with the correct path, but when mingw32-make.exe is executing, the path is now garbled:

    C:/workspace/pe±a/build2/CMakeFiles/CMakeTmp
    

    The easiest way to avoid this issue is to simply change your project path to be one that does not contain non-ASCII characters.

    Another option would be to use a different generator (something other than MinGW Makefiles). For example, Visual Studio configures and builds correctly, even though the non-ASCII characters are in the project path:

    > cmake -G"Visual Studio 16 2019" ..
    Re-run cmake no build system arguments
    C:/workspace/peña
    -- The CXX compiler identification is MSVC 19.23.28106.4
    -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe
    -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe - works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Configuring done
    -- Generating done
    -- Build files have been written to: C:/workspace/peña/build