我读了Using a Mac to cross-compile Linux binaries并从中运行了一些命令。在macOS上运行cargo build
时,出现以下错误:
CMake Error at CMakeLists.txt:31 (project):
The CMAKE_C_COMPILER:
x86_64-unknown-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.
我该如何解决?
我尝试设置CC
环境变量没有成功:
$ which gcc
/usr/bin/gcc
$ export CC="/usr/bin/gcc"
$ cargo build
和
$ xcrun -find cc
/Library/Developer/CommandLineTools/usr/bin/cc
$ export CC="/Library/Developer/CommandLineTools/usr/bin/cc"
$ echo $CC
/Library/Developer/CommandLineTools/usr/bin/cc
然后我收到了同样的错误。
答案 0 :(得分:0)
我通过运行以下命令解决了该问题:
$ export TARGET_CC=x86_64-linux-musl-gcc
$ echo $TARGET_CC
x86_64-linux-musl-gcc
$ which x86_64-linux-musl-gcc
/usr/local/bin/x86_64-linux-musl-gcc
$ export CC="/usr/local/bin/x86_64-linux-musl-gcc"
$ echo $CC
/usr/local/bin/x86_64-linux-musl-gcc
$ cargo build