Conan: creating package example doesn't work. No CMAKE_CXX_COMPILER could be found.

Created on 18 Jun 2017  ·  19Comments  ·  Source: conan-io/conan

Hello world example from http://docs.conan.io/en/latest/packaging/getting_started.html doesn't work on my windows 10 machine. What am I doing wrong?
```
islama@FRWN14IT MINGW64 ~/cpp/conan/mypkg
$ conan test_package
Exporting package recipe
Linter warnings
WARN: Linter. Line 2: Unused import os
WARN: Conanfile doesn't have 'description'.
It is recommended to add it as attribute
Hello/0.1@demo/testing: A new conanfile.py version was exported
Hello/0.1@demo/testing: Folder: C:Usersislama.conandataHello0.1demotestingexport
Requirements
Hello/0.1@demo/testing from local
Packages
Hello/0.1@demo/testing:63da998e3642b50bee33f4449826b2d623661505

Hello/0.1@demo/testing: WARN: Forced build from source
Hello/0.1@demo/testing: Building your package in C:Usersislama.conandataHello0.1demotestingbuild63da998e3642b50bee33f4449826b2d623661505
Hello/0.1@demo/testing: Configuring sources in C:Usersislama.conandataHello0.1demotestingsource
Cloning into 'hello'...
remote: Counting objects: 17, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 17 (delta 3), reused 17 (delta 3), pack-reused 0
Unpacking objects: 100% (17/17), done.
Switched to a new branch 'static_shared'
Branch static_shared set up to track remote branch static_shared from origin.
Hello/0.1@demo/testing: Copying sources to build folder
Hello/0.1@demo/testing: Generated cmake created conanbuildinfo.cmake
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:1 (PROJECT):
No CMAKE_C_COMPILER could be found.

CMake Error at CMakeLists.txt:1 (PROJECT):
No CMAKE_CXX_COMPILER could be found.

-- Configuring incomplete, errors occurred!
See also "C:/Users/islama/.conan/data/Hello/0.1/demo/testing/build/63da998e3642b50bee33f4449826b2d623661505/CMakeFiles/CMakeOutput.log".
See also "C:/Users/islama/.conan/data/Hello/0.1/demo/testing/build/63da998e3642b50bee33f4449826b2d623661505/CMakeFiles/CMakeError.log".

Hello/0.1@demo/testing: ERROR: Package '63da998e3642b50bee33f4449826b2d623661505' build failed
Hello/0.1@demo/testing: WARN: Build folder C:Usersislama.conandataHello0.1demotestingbuild63da998e3642b50bee33f4449826b2d623661505
ERROR: Hello/0.1@demo/testing: Error in build() method, line 27
self.run('cmake hello %s %s' % (cmake.command_line, shared))
ConanException: Error 1 while executing cmake hello -G "Visual Studio 14 2015 Win64" -DCONAN_LINK_RUNTIME="/MD" -DCONAN_EXPORTED="1" -DCONAN_COMPILER="Visual Studio" -DCONAN_COMPILER_VERSION="14" -DBUILD_SHARED_LIBS="OFF" -DCONAN_CXX_FLAGS="/MP8" -DCONAN_C_FLAGS="/MP8" -Wno-dev```

question

All 19 comments

Hi @islamaliev

What compiler or compilers do you have installed in your machine? Please note that conan does not install a compiler itself.

When you run conan for the first time, it will try to auto-detect installed compilers, print them to terminal and finally store them in your <userhome>/.conan/conan.conf file. You can check its contents, and to repeat the process you can just remove that file, and run conan again. Please copy the output here. Thanks!

well, the first time I ran conan it showed me this

It seems to be the first time you've ran conan
Auto detecting your dev setup to initialize conan.conf
Found clang 4.0
Default conan.conf settings
        os=Windows
        arch=x86_64
        compiler=clang
        compiler.version=4.0
        compiler.libcxx=libstdc++
        build_type=Release

but then I changed default settings so that it looks like this

[settings_defaults]

arch=x86_64
build_type=Release
compiler=Visual Studio
compiler.runtime=MD
compiler.version=14
os=Windows

it worked at least for tutorial with mytimer from http://docs.conan.io/en/latest/getting_started.html

And btw, compiling manually with cmake works fine.

That is weird... it seems conan was not able to detect your Visual Studio installation, neither is able to do CMake when run from conan. Are you compiling with cmake manually using the "Visual Studio 14 Win64" generator?

Do you have the VS140COMNTOOLS environment variable defined?

Ping me in the email if you are online an want to chat, maybe we can try to debug this.

Hi James,

I have VS 15 and so I do
cmake -G "Visual Studio 15 Win64" ..

Among other output that this command produce there are these lines:
-- The C compiler identification is MSVC 19.10.25019.0
-- The CXX compiler identification is MSVC 19.10.25019.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual
Studio/2017/Community/VC/Tools/MSVC/14.10.25017/bin/HostX86/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual
Studio/2017/Community/VC/Tools/MSVC/14.10.25017/bin/HostX86/x64/cl.exe --
works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual
Studio/2017/Community/VC/Tools/MSVC/14.10.25017/bin/HostX86/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual
Studio/2017/Community/VC/Tools/MSVC/14.10.25017/bin/HostX86/x64/cl.exe --
works

I can also do cmake --build.

We can do it tomorrow at 9pm CEST if you want.

Cheers,
Islam

On Sun, Jun 18, 2017 at 11:20 PM, James notifications@github.com wrote:

Ping me in the email if you are online an want to chat, maybe we can try
to debug this.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/conan-io/conan/issues/1402#issuecomment-309303722,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AD6i025-7pivPUmV1t45c2Z6DIsC_YDCks5sFZS4gaJpZM4N9eao
.

I see. Then the reason is that you have to declare manually the variable VS150COMNTOOLS, because Visual Studio 15 does not add it to the environment anymore, and conan needs it to be able to use it. I don't know exactly why, but cmake is able to do it when run isolated, but when run as subprocess, it won't be able to find the VS 15.

I have defined in my Win 10 box (system wide):

VS150COMNTOOLS=C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/Tools/

Please try it. Tomorrow I will be available from approx 9:30 CEST, ping me in twitter or [email protected]. Thanks!

I have the same problem, I guess.
CMake runs OK.
I have set the VS150COMNTOOLS environment variable on my Windows box (global) and Conan can't seem to be able to use it. :(

Solution: make sure that you are using VS15:

  1. Define the VS150COMNTOOLS env var as above
  2. Define your conan.conf default settings to
arch=x86_64
build_type=Release
compiler=Visual Studio
compiler.runtime=MD
compiler.version=15
os=Windows

Or define the settings in the command line arguments, or in a profile and pass the profile as command line argument.

I have done that, in a lot of different ways, see #1231 , but for some reason it still fails.
Even when I call set VS150COMNTOOLS=C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/Tools/ in the command console itself before running Conan.

I think I will bite the bullet and simply install a previous version of Visual Studio :)

I think VS150COMNTOOLS is actually defined by default by the installer? It seemed to be there on my machine (not currently on Windows, need to check).

@jacmoe, have you tried invoking conan from the "Visual Studio 2017 x64 native command prompt" (or something along those lines) that you can find in the start menu ?

Hi @jcar87
No, VS150COMNTOOLS is not defined by the installer, it has to be manually defined by the user (it can be done in the system env-vars, so it is enough to do it once after installing VS2017)

The problem with launching things from a VS command prompt (for 2017 or older versions), is that it is not a reproducible build, users should be able to do it in different terminals (I use cmder in Win, for example). Also you can only build for that version, what happens if you want to build for different VS versions? You would need to open different prompts for each one, not very convenient. So we recommend setting the env-var, and forgetting about it.

Yup, just checked, no VS150COMNTOOLS.
Apparently since version 15.2 of VS2017, they now bundle vswhere.exe which should help.
https://blogs.msdn.microsoft.com/heaths/2017/04/21/vswhere-is-now-installed-with-visual-studio-2017/

So if %ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe exists, we can locate the vcvarsall.bat (relative to the returned installationPath, in the Auxiliary/Build subfolder)

I guess that would work but that would still leave people with versions <15.2 a bit in the dark.

Does conan set the env vars based on the compiler version passed to conanfile?

As for having to launch different prompts for different compilers, if I use a CMake generator on windows that is NOT "Visual Studio xxxx" (e.g., nmake files, jom, ninja), CMake relies on an already-set environment. Not too different than setting CC/CXX on Linux. Although I guess the tricky bit here is actually finding the correct compiler path in the first place.

Ey, thanks for telling, the bundling of vswhere will make things easier, opened a dedicated issue for it: https://github.com/conan-io/conan/issues/1469

Conan does not set automatically any env-var, users have to do it. E.g. if you have gcc 5.4 in a custom path and want conan to use it, it is not enough to specify -s compiler=gcc -s compiler.version=5.4, but you will also have to specify -e CC=/your/path/to/gcc-54. For this, profiles are recommended.

Regarding the prompt, that is true, but the thing is that conan needs to be able to tell those build systems to run in an environment with the specified VS, to achieve reproducibility. This can be done in conanfiles with the tools.vcvars_command helper, and it already works fine for all VS but 2017, which doesn't have the env-var by default.

Great! One thing I'm not entirely sure is whether the vs installer always places that file there, even if the user specifies a different install location.

Back onto the OP's issue, I've been digging and I'm very surprised that "cmake" didn't find the VS compiler. When passing "Visual Studio 2017", CMake does not rely on any environment variable, but rather they query a COM component through the Windows API.
Microsoft sample code: (https://github.com/Microsoft/vs-setup-samples)
CMake implementation: https://github.com/Kitware/CMake/commit/18c8278b622e4cb9b155c5dc4ceac93322bed85f

So CMake should find Visual Studio 2017 regardless of environment variables.

One interesting thing I've noticed in the OP's post is that mingw64 is being used as the shell environment. Which would explain why conan set clang 4.0 as the default setting. It may be that CMake behaves differently in that environment. Or perhaps the CMake version is not the minimum required (>=3.7 for VS2017).

Hi @islamaliev , @jacmoe , @jcar87

Conan has implemented the location of VS2017 with vswhere.exe, so no longer requires to define the VS150COMNTOOLS env-var manually. It has been released in conan 0.26

Also, tracked down some of the issues of CMake with VS2017, it happens that installation of VS2017 might come without the system SDK, that cmake uses (rc.exe) to build the test example, so without it, cmake might be unable to locate VS. Reinstalling the SDK fixes the issue. The bad thing is that it also messes up the VS2015 installation, which might also require to reinstall the SDK for it.

So I think this issue is solved now and can be closed. It would be great if you could upgrade to latest conan and re-check. Do not hesitate to re-open or comment if need some help. Thanks very much!

I just checked - better late than never, right? and it does indeed work great! 😄

I didn't have time to use a Conan project, and just running conan didn't create any configuration, but then I realized that Conan now has a separate configuration creation command, and all was well.
Great work! 👍

Thanks very much @jacmoe for telling! Yes, we love feedback, it is never late :)

I'm hitting the same problem with a package I'm creating.

Environment:

  • Win 10 x64
  • MSVC 2019 (16.2) Professional
  • CMake 3.15
  • Conan 1.17.2

The conan install [PACKAGE_NAME] --build works without problems, using CMake as build step, but if I run conan test test_package [PACKAGE_NAME], then CMake complains with the message
No CMAKE_CXX_COMPILER could be found.

I've called the vcvars64.bat script before doing anything, but it still hits it without reasons.

The build() function in the test_package CMakeLists.txt looks like this:

def build(self):
    cmake = CMake(self)
    cmake.configure()
    cmake.build()

The same package can be built under Linux (and same conan and CMake versions) without problems.

The interesting thing is that the generated CMakeCache.txt as the correct variables:

CMAKE_GENERATOR:INTERNAL=Visual Studio 16 2019

CMAKE_PLATFORM:INTERNAL=x64

CMAKE_GENERATOR_TOOLSET is empty

CMAKE_GENERATOR_INSTANCE:INTERNAL=C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional

Was this page helpful?
0 / 5 - 0 ratings