Open aiyolo opened 1 year ago
everything is well when I don't specify Ninja as generator(then Visual Studio 16 will be choosed as default generator), but if I specify Ninja as generator, the errors comes up.
Hi @aiyolo
Thanks for your question.
This happens because the Ninja
generator does not locate the VS installation by itself (this is something between CMake, Ninja and VS, not specific of Conan).
So it is necessary to activate the VS prompt, of the compiler you want to use. In the conan install
process Conan generates automatically a conanbuild.bat
script that activate all the necessary environment (not only the vcvars, for example it could also activate the PATH to use a modern cmake
version that was required by Conan with tool_requires("cmake/[>=3.25]")
).
This works:
$ build\Debug\generators\conanbuild.bat
conanvcvars.bat: Activating environment Visual Studio 17 - amd64 - vcvars_ver=14.3
[vcvarsall.bat] Environment initialized for: 'x64'
$ cmake --preset conan-debug
Preset CMake variables:
CMAKE_BUILD_TYPE="Debug"
CMAKE_POLICY_DEFAULT_CMP0091="NEW"
CMAKE_TOOLCHAIN_FILE:FILEPATH="C:\----\build\Debug\generators\conan_toolchain.cmake"
-- Using Conan toolchain: C:/---/build/Debug/generators/conan_toolchain.cmake
-- Conan toolchain: C++ Standard 14 with extensions OFF
-- Conan toolchain: Setting BUILD_SHARED_LIBS = OFF
-- The CXX compiler identification is MSVC 19.36.32534.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to:
There still remains a problem, Since I installed qt mingw g++ in my computer, after run conanbuild.bat
, and cmake --preset conan-debug
, mingw g++ is detected as default compiler instead of visual studio, why this happens?
$ \build\conanbuild.bat
conanvcvars.bat: Activating environment Visual Studio 17 - amd64 - vcvars_ver=14.3
[vcvarsall.bat] Environment initialized for: 'x64'
$ cmake --preset conan-debug
Preset CMake variables:
CMAKE_BUILD_TYPE="Debug"
CMAKE_POLICY_DEFAULT_CMP0091="NEW"
CMAKE_TOOLCHAIN_FILE:FILEPATH="C:\Users\zhu\Documents\qiaoyi\cmake-qt-template\conan-template\build\conan_toolchain.cmake"
-- Using Conan toolchain: C:/Users/zhu/Documents/qiaoyi/cmake-qt-template/conan-template/build/conan_toolchain.cmake
-- Conan toolchain: C++ Standard 14 with extensions OFF
-- The CXX compiler identification is GNU 7.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Qt/Qt5.13.2/Tools/mingw730_64/bin/c++.exe - skipped
That might be an extra side effect of using Ninja generator, that can do its own thing if things are not defined how it expects it to be, and as it is not a Microsoft thing, it might prioritize other compilers if they are found with higher priority, and it has not been explicitly told otherwise.
Maybe the CC/CXX
env-vars are defined, or just that qt compiler is prioritized in the PATH (by the way, it that is not your intended default compiler, I'd recommend to remove it from the PATH env-var).
I don't know how that mingw qt works, but maybe the solution is to explicitly define something like this in the profile:
[conf]
tools.build:compiler_executables={"c": "cl", "cpp": "cl"}
In any case, I'd recommend:
I just ran env
to recheck my PATH, but I didn't find CC/CXX
in PATH, and there is no qt mingw g++
then I set tools.build:compiler_executables={"c": "cl", "cpp": "cl"}
in my profile, and rut it again, but it seems I need to provide the full path of my msvc compiler.
$ cmake --preset conan-debug
Preset CMake variables:
CMAKE_BUILD_TYPE="Debug"
CMAKE_POLICY_DEFAULT_CMP0091="NEW"
CMAKE_TOOLCHAIN_FILE:FILEPATH="C:\Users\zhu\Documents\qiaoyi\cmake-qt-template\conan-template\build\conan_toolchain.cmake"
-- Using Conan toolchain: C:/Users/zhu/Documents/qiaoyi/cmake-qt-template/conan-template/build/conan_toolchain.cmake
-- Conan toolchain: C++ Standard 14 with extensions OFF
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:3 (project):
The CMAKE_CXX_COMPILER:
cl
is not a full path and was not found in the PATH.
CC and CXX could be environment variables, different from PATH. I guess you checked that they are not defined either?
How would be cmake aware of such a c++ compiler in C:/Qt/Qt5.13.2/Tools/mingw730_64/bin/c++.exe
if it is not in the PATH? The information should be somewhere, maybe in the build scripts, in the environment, etc. In Windows, CMake will not find arbitrary compilers in any random location unless the information is somewhere.
Now I have removed all compilers except for msvc, and continued with the previous approach, but it still doesn't work. the error is:
$ cmake --preset conan-release
Preset CMake variables:
CMAKE_BUILD_TYPE="Release"
CMAKE_POLICY_DEFAULT_CMP0091="NEW"
CMAKE_TOOLCHAIN_FILE:FILEPATH="C:\---\cmake-qt-template\conan-template\build\conan_toolchain.cmake"
-- Using Conan toolchain: C:/---/cmake-qt-template/conan-template/build/conan_toolchain.cmake
-- Conan toolchain: C++ Standard 14 with extensions OFF
-- The CXX compiler identification is MSVC 19.36.32535.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - broken
CMake Error at C:/---/scoop/apps/cmake/3.26.4/share/cmake-3.26/Modules/CMakeTestCXXCompiler.cmake:60 (message):
The C++ compiler
"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/zhu/Documents/qiaoyi/cmake-qt-template/conan-template/build/CMakeFiles/CMakeScratch/TryCompile-q7znqu
I don't know what could be happening, some things to check:
are you sure your VS 2022 is fully operational and working? Can you create a dummy "hello world" example (without Conan), create the project, open it with the IDE and build it? VS community requires a microsoft account and being logged-in, if not it might fail
Does the default configuration, no Ninja, works without problem? Can you please try the following:
conan new cmake_lib -d name=pkg -d version=0.1
conan create .
Also, sharing your CMakeLists.txt
would help. It is possible that there is something there that could be affecting.
FYI - this seemed to fix the issue for me! In my case, I needed to set version 10.22000.0 once, using cmake -DCMAKE_SYSTEM_VERSION=10.0.22000.0
- then it seemed to build fine from there.
Note - I had a cleanly installed version of VS 2022
Ok, that is interesting information thanks @sully7
Conan has a mechanism to explicitly define the cmake-system-version when it is necessary (this doesn't seem a Conan issue, but a CMake-VS version-Windows SDK version one): tools.cmake.cmaketoolchain:system_version
conf can be defined in profile or command line, and it will set the CMAKE_SYSTEM_VERSION in the toolchain
Could you @aiyolo, @sully7, please try it?
Here is what I try. for default profile
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.version=193
os=Windows
[conf]
tools.cmake.cmaketoolchain:system_version=10.0.19041.0
tools.cmake.cmaketoolchain:generator=Ninja
After run conan install ... and activate environment, it still has some problem.
$ cmake --preset conan-debug
Preset CMake variables:
CMAKE_BUILD_TYPE="Debug"
CMAKE_POLICY_DEFAULT_CMP0091="NEW"
CMAKE_TOOLCHAIN_FILE:FILEPATH="C:\Users\zhu\Documents\qiaoyi\cmake-qt-template\conan-template\build\conan_toolchain.cmake"
-- Using Conan toolchain: C:/Users/zhu/Documents/qiaoyi/cmake-qt-template/conan-template/build/conan_toolchain.cmake
-- Conan toolchain: C++ Standard 14 with extensions OFF
-- The CXX compiler identification is MSVC 19.29.30148.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - broken
CMake Error at C:/Users/zhu/scoop/apps/cmake/3.26.4/share/cmake-3.26/Modules/CMakeTestCXXCompiler.cmake:60 (message):
The C++ compiler
"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe"
is not able to compile a simple test program.
And without specifying ninja generator in my default profile, my project can be built successfully.
$ cmake --preset conan-default
Preset CMake variables:
CMAKE_POLICY_DEFAULT_CMP0091="NEW"
CMAKE_TOOLCHAIN_FILE:FILEPATH="C:\Users\zhu\Documents\qiaoyi\cmake-qt-template\conan-template\build\conan_toolchain.cmake"
-- Using Conan toolchain: C:/Users/zhu/Documents/qiaoyi/cmake-qt-template/conan-template/build/conan_toolchain.cmake
-- Conan toolchain: C++ Standard 14 with extensions OFF
-- The CXX compiler identification is MSVC 19.36.32535.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: Component target declared 'Boost::diagnostic_definitions'
-- Conan: Component target declared 'Boost::disable_autolinking'
-- Conan: Component target declared 'Boost::dynamic_linking'
I don't know why, but running cmake commands in devepoler powershell might solve this question.
Environment details
Steps to reproduce
conan profile detect --force
to generate a default profile*:tools.cmake.cmaketoolchain:generator=Ninja
in profile to use Ninja as generatorconan install . -of build -b missing -s build_type=Debug
run
cmake --preset conan-debug
, then errors comes up with:-- Configuring incomplete, errors occurred!
[settings] arch=x86_64 build_type=Release compiler=msvc compiler.cppstd=14 compiler.runtime=dynamic compiler.version=193 os=Windows
[conf] *:tools.cmake.cmaketoolchain:generator=Ninja
[requires] boost/1.78.0
[generators] CMakeDeps CMakeToolchain
cmake_minimum_required(VERSION 3.17)
project(network-assist LANGUAGES CXX) ...