Closed iXavierLiu closed 6 months ago
If you use the CMake integration and set CMAKE_CXX_COMPILER
, you only set the CMAKE_CXX_COMPILER
of your project, not the c++ compiler used to compile vcpkg packages. You have to set the CC
or CXX
env vars or use different triplets with custom toolchains.
If you use the CMake integration and set
CMAKE_CXX_COMPILER
, you only set theCMAKE_CXX_COMPILER
of your project, not the c++ compiler used to compile vcpkg packages. You have to set theCC
orCXX
env vars or use different triplets with custom toolchains.
In fact, I have tested it before, but in order to prevent the issue from being too lengthy, I did not put it up.
After I set the CC and CXX variables
❯ rm -rf out
❯ export CC=`where gcc-13`
❯ export CXX=`where g++-13`
❯ cmake --preset=osx-gcc
Preset CMake variables:
CMAKE_BUILD_TYPE="Debug"
CMAKE_CXX_COMPILER="/opt/homebrew/bin/g++-13"
CMAKE_C_COMPILER="/opt/homebrew/bin/gcc-13"
CMAKE_INSTALL_PREFIX="/Users/xavier/workspace/test/out/install/osx-gcc"
CMAKE_TOOLCHAIN_FILE="/Users/xavier/workspace/vcpkg/scripts/buildsystems/vcpkg.cmake"
-- Running vcpkg install
Fetching registry information from https://github.com/microsoft/vcpkg (HEAD)...
Detecting compiler hash for triplet arm64-osx...
error: while detecting compiler information:
The log file content at "/Users/xavier/workspace/vcpkg/buildtrees/detect_compiler/stdout-arm64-osx.log" is:
-- Configuring arm64-osx-rel
CMake Error at scripts/cmake/vcpkg_execute_required_process.cmake:112 (message):
Command failed: /opt/homebrew/Cellar/cmake/3.28.3/bin/cmake /Users/xavier/workspace/vcpkg/scripts/detect_compiler -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/Users/xavier/workspace/vcpkg/packages/detect_compiler_arm64-osx -DCMAKE_MAKE_PROGRAM=/Users/xavier/workspace/vcpkg/downloads/tools/ninja/1.10.2-osx/ninja -DCMAKE_SYSTEM_NAME=Darwin -DBUILD_SHARED_LIBS=OFF -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=/Users/xavier/workspace/vcpkg/scripts/toolchains/osx.cmake -DVCPKG_TARGET_TRIPLET=arm64-osx -DVCPKG_SET_CHARSET_FLAG=ON -DVCPKG_PLATFORM_TOOLSET=external -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON -DCMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP=TRUE -DCMAKE_VERBOSE_MAKEFILE=ON -DVCPKG_APPLOCAL_DEPS=OFF -DCMAKE_TOOLCHAIN_FILE=/Users/xavier/workspace/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION=ON -DVCPKG_CXX_FLAGS= -DVCPKG_CXX_FLAGS_RELEASE= -DVCPKG_CXX_FLAGS_DEBUG= -DVCPKG_C_FLAGS= -DVCPKG_C_FLAGS_RELEASE= -DVCPKG_C_FLAGS_DEBUG= -DVCPKG_CRT_LINKAGE=dynamic -DVCPKG_LINKER_FLAGS= -DVCPKG_LINKER_FLAGS_RELEASE= -DVCPKG_LINKER_FLAGS_DEBUG= -DVCPKG_TARGET_ARCHITECTURE=arm64 -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_BINDIR:STRING=bin -D_VCPKG_ROOT_DIR=/Users/xavier/workspace/vcpkg -DZ_VCPKG_ROOT_DIR=/Users/xavier/workspace/vcpkg -D_VCPKG_INSTALLED_DIR=/Users/xavier/workspace/test/out/build/osx-gcc/vcpkg_installed -DVCPKG_MANIFEST_INSTALL=OFF -DCMAKE_OSX_ARCHITECTURES=arm64
Working Directory: /Users/xavier/workspace/vcpkg/buildtrees/detect_compiler/arm64-osx-rel
Error code: 1
See logs for more information:
/Users/xavier/workspace/vcpkg/buildtrees/detect_compiler/config-arm64-osx-rel-CMakeCache.txt.log
/Users/xavier/workspace/vcpkg/buildtrees/detect_compiler/config-arm64-osx-rel-out.log
/Users/xavier/workspace/vcpkg/buildtrees/detect_compiler/config-arm64-osx-rel-err.log
Call Stack (most recent call first):
scripts/cmake/vcpkg_configure_cmake.cmake:344 (vcpkg_execute_required_process)
scripts/detect_compiler/portfile.cmake:18 (vcpkg_configure_cmake)
scripts/ports.cmake:170 (include)
error: vcpkg was unable to detect the active compiler's information. See above for the CMake failure output.
-- Running vcpkg install - failed
CMake Error at /Users/xavier/workspace/vcpkg/scripts/buildsystems/vcpkg.cmake:899 (message):
vcpkg install failed. See logs for more information:
/Users/xavier/workspace/test/out/build/osx-gcc/vcpkg-manifest-install.log
Call Stack (most recent call first):
/opt/homebrew/Cellar/cmake/3.28.3/share/cmake/Modules/CMakeDetermineSystem.cmake:170 (include)
CMakeLists.txt:3 (project)
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
-- Configuring incomplete, errors occurred!
It seems that the make program is missing, so I added "CMAKE_MAKE_PROGRAM": "/usr/bin/make"
to osx-gcc
, then
❯ rm -rf out
❯ cmake --preset=osx-gcc
Preset CMake variables:
CMAKE_BUILD_TYPE="Debug"
CMAKE_CXX_COMPILER="/opt/homebrew/bin/g++-13"
CMAKE_C_COMPILER="/opt/homebrew/bin/gcc-13"
CMAKE_INSTALL_PREFIX="/Users/xavier/workspace/test/out/install/osx-gcc"
CMAKE_MAKE_PROGRAM="/usr/bin/make"
CMAKE_TOOLCHAIN_FILE="/Users/xavier/workspace/vcpkg/scripts/buildsystems/vcpkg.cmake"
-- Running vcpkg install
Fetching registry information from https://github.com/microsoft/vcpkg (HEAD)...
Detecting compiler hash for triplet arm64-osx...
error: while detecting compiler information:
The log file content at "/Users/xavier/workspace/vcpkg/buildtrees/detect_compiler/stdout-arm64-osx.log" is:
-- Configuring arm64-osx-rel
CMake Error at scripts/cmake/vcpkg_execute_required_process.cmake:112 (message):
Command failed: /opt/homebrew/Cellar/cmake/3.28.3/bin/cmake /Users/xavier/workspace/vcpkg/scripts/detect_compiler -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/Users/xavier/workspace/vcpkg/packages/detect_compiler_arm64-osx -DCMAKE_MAKE_PROGRAM=/Users/xavier/workspace/vcpkg/downloads/tools/ninja/1.10.2-osx/ninja -DCMAKE_SYSTEM_NAME=Darwin -DBUILD_SHARED_LIBS=OFF -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=/Users/xavier/workspace/vcpkg/scripts/toolchains/osx.cmake -DVCPKG_TARGET_TRIPLET=arm64-osx -DVCPKG_SET_CHARSET_FLAG=ON -DVCPKG_PLATFORM_TOOLSET=external -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON -DCMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP=TRUE -DCMAKE_VERBOSE_MAKEFILE=ON -DVCPKG_APPLOCAL_DEPS=OFF -DCMAKE_TOOLCHAIN_FILE=/Users/xavier/workspace/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION=ON -DVCPKG_CXX_FLAGS= -DVCPKG_CXX_FLAGS_RELEASE= -DVCPKG_CXX_FLAGS_DEBUG= -DVCPKG_C_FLAGS= -DVCPKG_C_FLAGS_RELEASE= -DVCPKG_C_FLAGS_DEBUG= -DVCPKG_CRT_LINKAGE=dynamic -DVCPKG_LINKER_FLAGS= -DVCPKG_LINKER_FLAGS_RELEASE= -DVCPKG_LINKER_FLAGS_DEBUG= -DVCPKG_TARGET_ARCHITECTURE=arm64 -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_BINDIR:STRING=bin -D_VCPKG_ROOT_DIR=/Users/xavier/workspace/vcpkg -DZ_VCPKG_ROOT_DIR=/Users/xavier/workspace/vcpkg -D_VCPKG_INSTALLED_DIR=/Users/xavier/workspace/test/out/build/osx-gcc/vcpkg_installed -DVCPKG_MANIFEST_INSTALL=OFF -DCMAKE_OSX_ARCHITECTURES=arm64
Working Directory: /Users/xavier/workspace/vcpkg/buildtrees/detect_compiler/arm64-osx-rel
Error code: 1
See logs for more information:
/Users/xavier/workspace/vcpkg/buildtrees/detect_compiler/config-arm64-osx-rel-CMakeCache.txt.log
/Users/xavier/workspace/vcpkg/buildtrees/detect_compiler/config-arm64-osx-rel-out.log
/Users/xavier/workspace/vcpkg/buildtrees/detect_compiler/config-arm64-osx-rel-err.log
Call Stack (most recent call first):
scripts/cmake/vcpkg_configure_cmake.cmake:344 (vcpkg_execute_required_process)
scripts/detect_compiler/portfile.cmake:18 (vcpkg_configure_cmake)
scripts/ports.cmake:170 (include)
error: vcpkg was unable to detect the active compiler's information. See above for the CMake failure output.
-- Running vcpkg install - failed
CMake Error at /Users/xavier/workspace/vcpkg/scripts/buildsystems/vcpkg.cmake:899 (message):
vcpkg install failed. See logs for more information:
/Users/xavier/workspace/test/out/build/osx-gcc/vcpkg-manifest-install.log
Call Stack (most recent call first):
/opt/homebrew/Cellar/cmake/3.28.3/share/cmake/Modules/CMakeDetermineSystem.cmake:170 (include)
CMakeLists.txt:3 (project)
-- Configuring incomplete, errors occurred!
config-arm64-osx-rel-err.log
:
CMake Error:
Running
'/Users/xavier/workspace/vcpkg/downloads/tools/ninja/1.10.2-osx/ninja' '-C' '/Users/xavier/workspace/vcpkg/buildtrees/detect_compiler/arm64-osx-rel/CMakeFiles/CMakeScratch/TryCompile-j8qDDF' '-t' 'recompact'
failed with:
ninja: error: CMakeFiles/rules.ninja:21: lexing error
CMake Error at /opt/homebrew/Cellar/cmake/3.28.3/share/cmake/Modules/CMakeDetermineCompilerABI.cmake:57 (try_compile):
Failed to generate test project build system.
Call Stack (most recent call first):
/opt/homebrew/Cellar/cmake/3.28.3/share/cmake/Modules/CMakeTestCCompiler.cmake:26 (CMAKE_DETERMINE_COMPILER_ABI)
CMakeLists.txt:11 (enable_language)
CMake Warning:
Value of CMAKE_C_COMPILER_ARG1 contained a newline; truncating
This seems to be an internal error of vcpkg, so I don't think selecting the compiler in manifest mode via the CC
and CXX
variables is the correct approach.
No. Set CC and CXX in the preset and don't use where
.
This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 28 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.
No. Set CC and CXX in the preset and don't use
where
.
This does fix the problem, but it is still confusing to set variables this way, because one would think vcpkg would read the default values for CC and CXX from bash, but it obviously does not. Anyway, thanks for your answer.
CC
and CXX
are environment variables. They influence both CMake projects, incl. vcpkg ports.
CMAKE_C_COMPILER
and CMAKE_CXX_COMPILER
are CMake variables. They influence CMake projects. They are not passed through from the top-level project to vcpkg ports.
In fact, the environment variables may interfere with crossbuilds in undesired ways.
where ...
is just a distractor here. It is meant to be expanded by the shell before being passed into CMake. It won't work if it is passed literally into CMake.
Environment
Apple M3 Pro(macOS Sonoma 14.3.1)
clang(Apple clang version 15.0.0)
,g++(g++-13 (Homebrew GCC 13.2.0) 13.2.0)
To Reproduce
Steps to reproduce the behavior:
Consider the following two scenarios:
INSTALL-CLANG
with default compiler(clang), ABI is28823f79dc4bbccc7130554e4be16b5982020f9ac825f9cd3c07b94c6af54233
INSTALL-GCC
with gcc compiler, ABI is95dd47b37b611a080722c3c12cdce2392cd0bf0956fdc33017e4960f904c56f7
Pay attention to the first two lines.The ABIs of
INSTALL-CLANG
andINSTALL-GCC
are obviously different because they are built using different compilers.Then consider the following situation:
CMakeUserPresets.json
has two presets, one namedosx-gcc
and the other namedosx-clang
. They only have different compilers.In classic mode, if
osx-gcc
preset uses the installation ofINSTALL-GCC
andosx-clang
preset uses the installation ofINSTALL-CLANG
, there will be no ABI problems.If
osx-gcc
preset uses installation ofINSTALL-clang
, it will cause ABI problems when building, and vice versa.They worked well as expected.
main body
In manifest mode,
vcpkg.json
is very simpleConfiguration using
osx-clang
presetConfiguration using
osx-clang
presetAs you can see, their ABIs are the same, although the specified compiler is different, where ABI of
osx-clang
is correct. errors will be reported when buildingosx-gcc
.It's not clear to me how vcpkg specifies a specific compiler in manifest mode, I tried specifying via
CMAKE_CXX_COMPILER
but it doesn't seem to work.I tried looking up the problem through the documentation and google, but found nothing. Did I miss something?