1
votes

I am building a C++ project with Clang 3.8 and CMake 3.7 on Windows, but Clang emits an error in configure like below.

    Determining if the CXX compiler works failed with the following output:
    Change Dir: C:/tools/k.build/CMakeFiles/CMakeTmp

    Run Build Command:"C:/tools/ninja.exe" "cmTC_c0004"
    [1/2] Building CXX object CMakeFiles/cmTC_c0004.dir/testCXXCompiler.cxx.obj
    [2/2] Linking CXX executable cmTC_c0004.exe

    FAILED: cmTC_c0004.exe 

    cmd.exe /C "cd . && C:\tools\llvm-3.8.1.build\Release\bin\clang++.exe     CMakeFiles/cmTC_c0004.dir/testCXXCompiler.cxx.obj  -o cmTC_c0004.exe -Wl,--out-implib,libcmTC_c0004.dll.a -Wl,--major-image-version,0,--minor-image-version,0   && cd ."

    LINK : warning LNK4044: unrecognized option '/-out-implib'; ignored
    LINK : warning LNK4044: unrecognized option '/-major-image-version'; ignored
    LINK : warning LNK4044: unrecognized option '/-minor-image-version'; ignored
    LINK : fatal error LNK1181: cannot open input file 'libcmTC_c0004.dll.a'

    clang++.exe: error: linker command failed with exit code 1181 (use -v to see invocation)

    ninja: build stopped: subcommand failed.

Strange thing is that no file exists in CMakeFiles/CMakeTmp/. How can I get it to work?

1
Did you try to delete binary output k.build and try from scratch again? Looks like you switched compilers e.g. from gcc to clang in the same output directory. You could also try a minimal example like here.Florian
Somehow your configuration is broken. The options starting with /- are plain wrong, and .dll.a looks strange, too. How do you invoke CMake? What compiler does it detect?usr1234567
@Florian Yes, I deleted the outputs in k.build and tried some other settings again and again. The projects has been developed for Linux and I am porting it to Windows.HenryK
@usr1234567 I use cmake-gui with CMAKE_CXX_COMPILER_ID=Clang and CMAKE_CXX_COMPILER=path-to-clang++. CMakeLists.txt has originally been written for Linux and g++. Should it be modified for Windows?HenryK
Don't set the compiler ID, let CMake figure that out. Maybe you should try so set the C compiler, too?usr1234567

1 Answers

0
votes

Simply put, you are defining your toolchain wrong. CMake thinks you are using the MSVC compiler with a different path. See this question for a detailed answer. Note that you will still need MSVC or Cygwin as a build environment.