H. Desane
H. Desane

Reputation: 653

How can I fix "The CMAKE_C_COMPILER is not a full path and was not found in the PATH"?

I read Using a Mac to cross-compile Linux binaries and ran some commands from it. When I run cargo build on macOS, I receive the following error:

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.

How can I fix it?

I tried to set the CC environment variable with no success:

$ which gcc
/usr/bin/gcc
$ export CC="/usr/bin/gcc"
$ cargo build

and

$ 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

And then I received the same error.

Upvotes: 3

Views: 10490

Answers (1)

H. Desane
H. Desane

Reputation: 653

I solved it by running the following:

$ 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

Upvotes: 1

Related Questions