microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
23.26k stars 6.41k forks source link

How do I set the CC properly while installing a library #14466

Closed davidtavarez closed 2 years ago

davidtavarez commented 4 years ago

I'm trying to install a library like this:

$ vcpkg install --triplet arm64-linux zlib --debug

but it is failing...

$ cat /vcpkg/buildtrees/detect_compiler/config-arm64-linux-rel-out.log
-- Cross compiling arm64 on host x86_64, use cross compiler: aarch64-linux-gnu-g++/aarch64-linux-gnu-gcc
-- The C compiler identification is unknown
-- Configuring incomplete, errors occurred!
See also "/vcpkg/buildtrees/detect_compiler/arm64-linux-rel/CMakeFiles/CMakeOutput.log".
See also "/vcpkg/buildtrees/detect_compiler/arm64-linux-rel/CMakeFiles/CMakeError.log".

$ cat  /vcpkg/buildtrees/detect_compiler/config-arm64-linux-rel-err.log
CMake Error at CMakeLists.txt:11 (enable_language):
  The CMAKE_C_COMPILER:

    aarch64-linux-gnu-gcc

  is not a full path and was not found in the PATH.

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.

the environment variables are set like this:

$ env
GREP_COLOR=01;32
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.pdf=00;32:*.ps=00;32:*.txt=00;32:*.patch=00;32:*.diff=00;32:*.log=00;32:*.tex=00;32:*.doc=00;32:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
VCPKG_DEFAULT_TRIPLET=arm64-linux
ARCH=arm64
DEFAULT_DOCKCROSS_IMAGE=dockcross/linux-arm64:latest
CROSS_TRIPLE=aarch64-unknown-linux-gnueabi
LESS= -iJr
HOSTNAME=87e0cd6b2e87
XCC_PREFIX=/usr/xcc
QEMU_SET_ENV=LD_LIBRARY_PATH=/usr/xcc/aarch64-unknown-linux-gnueabi/lib:/usr/xcc/aarch64-unknown-linux-gnueabi/aarch64-unknown-linux-gnueabi/sysroot
VCPKG_CMAKE_SYSTEM_NAME=Linux
CC=/usr/xcc/aarch64-unknown-linux-gnueabi/bin/aarch64-unknown-linux-gnueabi-gcc
PWD=/
HOME=/root
AS=/usr/xcc/aarch64-unknown-linux-gnueabi/bin/aarch64-unknown-linux-gnueabi-as
AR=/usr/xcc/aarch64-unknown-linux-gnueabi/bin/aarch64-unknown-linux-gnueabi-ar
FC=/usr/xcc/aarch64-unknown-linux-gnueabi/bin/aarch64-unknown-linux-gnueabi-gfortran
VCPKG_FORCE_SYSTEM_BINARIES=1
CXX=/usr/xcc/aarch64-unknown-linux-gnueabi/bin/aarch64-unknown-linux-gnueabi-g++
TERM=xterm
SHLVL=1
CROSS_ROOT=/usr/xcc/aarch64-unknown-linux-gnueabi
CROSS_COMPILE=aarch64-unknown-linux-gnueabi-
QEMU_LD_PREFIX=/usr/xcc/aarch64-unknown-linux-gnueabi/aarch64-unknown-linux-gnueabi/sysroot
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/xcc/aarch64-unknown-linux-gnueabi/bin
VCPKG_TARGET_ARCHITECTURE=arm64
VCPKG_LIBRARY_LINKAGE=static
PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig
HISTSIZE=3000
CMAKE_TOOLCHAIN_FILE=/usr/xcc/aarch64-unknown-linux-gnueabi/Toolchain.cmake
CPP=/usr/xcc/aarch64-unknown-linux-gnueabi/bin/aarch64-unknown-linux-gnueabi-cpp
LD=/usr/xcc/aarch64-unknown-linux-gnueabi/bin/aarch64-unknown-linux-gnueabi-ld
_=/usr/bin/env

since this commit I am not able to install any library https://github.com/microsoft/vcpkg/commit/5e4d2fab8605a21972cb990ba49ade83ef19ffbf

How do I set the proper toolchain file?

NancyLi1013 commented 4 years ago

Hi @davidtavarez Thanks for posting this issue. Since this is a community-triplet issue, which is an unofficial triplet in vcpkg now.

Hope this reference can help you some. https://stackoverflow.com/questions/54633860/how-can-i-fix-the-cmake-c-compiler-is-not-a-full-path-and-was-not-found-in-the

Thanks.

davidtavarez commented 4 years ago

Thanks @NancyLi1013

But if I'm using a custom triplet setting the CMAKE_CXX_COMPILER to aarch64-unknown-linux-gnueabi-g++ (as my env) I should not have any problems... but I do:

arm64-unknown-linux-static.cmake

set(VCPKG_TARGET_ARCHITECTURE arm64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE static)

set(VCPKG_CMAKE_SYSTEM_NAME Linux)

set(CMAKE_CXX_COMPILER "aarch64-unknown-linux-gnueabi-g++")
set(CMAKE_C_COMPILER "aarch64-unknown-linux-gnueabi-gcc")

if(NOT CMAKE_HOST_SYSTEM_PROCESSOR)
    execute_process(COMMAND "uname" "-m" OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()

/vcpkg/vcpkg install --debug --overlay-triplets=/work/vcpkg/custom_triplets --triplet arm64-unknown-linux-static --overlay-ports=/work/vcpkg/custom_ports libsodium

[root:/] # cat /vcpkg/buildtrees/detect_compiler/config-arm64-unknown-linux-static-rel-err.log
CMake Error at CMakeLists.txt:11 (enable_language):
  The CMAKE_C_COMPILER:

    aarch64-linux-gnu-gcc

  is not a full path and was not found in the PATH.

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.
reynoldsbd commented 3 years ago

(Disclaimer: I work for MS, but not on vcpkg. I just happen to be hitting a similar issue)

Be sure not to confuse triplet and toolchain files. Triplet files are for configuring vcpkg's behavior via setting VCPKG_* variables, whereas toolchain files are for configuring CMake itself via CMAKE_* variables.

In some cases, vcpkg is smart enough to automatically set certain toolchain variables. For instance, VCPKG_TARGET_ARCHITECTURE is used to populate the value of CMAKE_SYSTEM_PROCESSOR. But many CMake settings (such as CMAKE_<lang>_COMPILER) do not have a corresponding VCPKG_* variable, so you'll need to chainload a custom toolchain file.

Try splitting the triplet file from your previous comment into two separate files. First the triplet file, arm64-unknown-linux-static.cmake:

set(VCPKG_TARGET_ARCHITECTURE arm64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE static)

set(VCPKG_CMAKE_SYSTEM_NAME Linux)

set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/arm64-unknown-linux-static-toolchain.cmake)

And a separate toolchain file, arm64-unknown-linux-static-toolchain.cmake:

set(CMAKE_CXX_COMPILER "aarch64-unknown-linux-gnueabi-g++")
set(CMAKE_C_COMPILER "aarch64-unknown-linux-gnueabi-gcc")

# You might not need this section, I believe vcpkg knows how to correctly populate
# if(NOT CMAKE_HOST_SYSTEM_PROCESSOR)
#     execute_process(COMMAND "uname" "-m" OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR OUTPUT_STRIP_TRAILING_WHITESPACE)
# endif()

@NancyLi1013 do you think it would make sense for vcpkg to support a new triplet setting (something like VCPKG_<lang>_COMPILER) so that chainloading a custom toolchain file is not necessary?

NancyLi1013 commented 3 years ago

Sorry, I'm also not clear about this.

@vicroms Could you please help comment something here?

JonLiu1993 commented 2 years ago

This issue hasn’t been updated more than 3 months, if it is still an issue, please reopen this issue.