1

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?

HenryK
  • 51
  • 2
  • 7
  • 2
    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](http://stackoverflow.com/questions/38171878/how-do-i-tell-cmake-to-use-clang-on-windows). – Florian Dec 20 '16 at 08:00
  • 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 Dec 20 '16 at 08:00
  • @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 Dec 20 '16 at 23:37
  • @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 Dec 20 '16 at 23:51
  • Don't set the compiler ID, let CMake figure that out. Maybe you should try so set the C compiler, too? – usr1234567 Dec 21 '16 at 11:19
  • @usr1234567 That didn't work. If the compiler IDs are not specified, CMake gives options for MSVC to Clang, such as `/nologo`. Do the environment variables like as CC and CXX affect the behaviour of CMake? – HenryK Dec 22 '16 at 00:18
  • Yes, they do, but CMAKE_C_COMPILER and CMAKE_CXX_COMPILER do the same. Have always clear your build directory? – usr1234567 Dec 22 '16 at 07:01
  • @usr1234567 Yes, I always cleared the build directory. After all, I have build the project with Visual Studio, not with Clang. – HenryK Feb 08 '17 at 05:27

1 Answers1

0

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.

Community
  • 1
  • 1
  • Do you mean that MSVC or Cygwin is required as CMAKE_GENERATOR? Ninja can't be used? – HenryK Dec 21 '16 at 06:51
  • I do not know. The linked question indicates that a build manager such as MSVC or Cygwin is required. I know CMake has added Ninja support since that question was answered. I think the main thing is to add the toolchain information in the way that answer suggests rather than the method you have used. – Norman B. Lancaster Dec 21 '16 at 12:18
  • MSVC, Cygwin and Ninja all can be the generator on Windows. However, the problem is about the compiler in this post. – Liu Hao Cheng Aug 01 '18 at 18:48