How to fix compiler identification unknown - Visual Studio 19

这一生的挚爱 提交于 2020-07-22 21:34:18

问题


When I try to load a open source project in Visual Studio cmake is asking to generate cache and getting the following error:

CMake generation started for configuration: 'x64-Debug'. 1> The toolchain file has changed (CMAKE_TOOLCHAIN_FILE). 1> Command line: "cmd.exe" /c ""C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="G:\Reference's\libiec61850-1.4.0\out\install\x64-Debug" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "G:\Reference's\libiec61850-1.4.0" 2>&1" 1> Working directory: G:\Reference's\libiec61850-1.4.0\out\build\x64-Debug 1> [CMake] -- The C compiler identification is unknown 1> [CMake] -- The CXX compiler identification is unknown 1> [CMake] CMake Error at G:\Reference's\libiec61850-1.4.0\CMakeLists.txt:4 (project): 1> [CMake] No CMAKE_C_COMPILER could be found. 1> [CMake] 1> [CMake]
Tell CMake where to find the compiler by setting either the environment 1> [CMake] variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to 1> [CMake] the compiler, or to the compiler name if it is in the PATH.

And in Cmake text file it is written as:

# automagically detect if we should cross-compile
if(DEFINED ENV{TOOLCHAIN})
    set(CMAKE_C_COMPILER    $ENV{TOOLCHAIN}gcc)
    set(CMAKE_CXX_COMPILER  $ENV{TOOLCHAIN}g++)
    set(CMAKE_AR    "$ENV{TOOLCHAIN}ar" CACHE FILEPATH "CW archiver" FORCE)
endif()

But the same project is building in clion. After reading few forums I tried installing individual components as well but still not able to get a fix for the above.


回答1:


Open up Developer Command Prompt for VS 2019.

Navigate to your source directory. (Looks like cd G:\Reference's\libiec61850-1.4.0)

and to the build directory from there cd out)

Run cmake -G 'Visual Studio 16 2019' -A x86 ../ or whatever platform you are targeting (Win32, x86, ARM, or ARM64)

Then build from Visual Studio or the command line using cmake --build .



来源:https://stackoverflow.com/questions/59986555/how-to-fix-compiler-identification-unknown-visual-studio-19

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!