External Issue: Clang not found when trying to compile a C file

22490, "twesterhout", "Clang not found when trying to compile a C file", "2023-06-07T10:24:36Z"

Suppose that I don't have any of the LLVM tools or Clang on my PATH, but properly set CHPL_HOST_CC, CHPL_HOST_CXX, CHPL_TARGET_CC, and CHPL_TARGET_CXX to the absolute paths of clang and clang++. Then, if I set CHPL_LLVM=system and CHPL_HOST_COMPILER=llvm, I expect the compiler to work, and indeed it does.

However, if I now try to do something like chpl --library code.chpl code.c (i.e. I'm asking Chapel to compile a C file), this results in an error:

error in exec: No such file or directory
child process exited with code 255
error: Compile C File

The issue turns out to be that chpl can't find Clang to compile the C source. This felt weird, so after this line

I inserted a print statement to display clangCC, clangCXX, and useLinkCXX. To my surprise both clangCC and clangCXX were empty, but useLinkCXX was set correctly. So as long as only linking was required, chpl called out to useLinkCXX, and there were no errors. This can be confirmed by pre-compiling code.c into code.o and passing that to the chpl --library call -- the command works fine.

So I looked at the helpComputeClangArgs that (I guess) sets the values of clangCC and clangCXX, and saw this:

So naturally I tried setting CHPL_LLVM_CLANG_C and CHPL_LLVM_CLANG_CXX environment variables, but to no avail. E.g. printchplenv --all --internal displays:

CHPL_LLVM: system *
  CHPL_LLVM_SUPPORT: system
  CHPL_LLVM_CONFIG: /nix/store/f1l9dlzsrjxangh9d2l0i3mjkyrkk3r6-llvm-14.0.6-dev/bin/llvm-config *
  CHPL_LLVM_VERSION: 14
  CHPL_LLVM_CLANG_C:  *
  CHPL_LLVM_CLANG_CXX:  *
  CHPL_LLVM_STATIC_DYNAMIC: dynamic
  CHPL_LLVM_TARGET_CPU: none

printchplenv clearly notices that I've set CHPL_LLVM_CLANG_C, but thinks it's still empty.

Anyway, I have a temporary workaround, but I have a feeling that there's a small bug somewhere.

Configuration Information

  • Output of chpl --version: chpl version 1.31.0 pre-release (xxxxxxxxxx) (basically main from one or two days ago)
  • Output of $CHPL_HOME/util/printchplenv --anonymize:
CHPL_TARGET_PLATFORM: linux64
CHPL_TARGET_COMPILER: llvm
CHPL_TARGET_ARCH: x86_64
CHPL_TARGET_CPU: none *
CHPL_LOCALE_MODEL: flat
CHPL_COMM: none
CHPL_TASKS: qthreads
CHPL_LAUNCHER: none
CHPL_TIMERS: generic
CHPL_UNWIND: system *
CHPL_MEM: jemalloc
CHPL_ATOMICS: cstdlib
CHPL_GMP: system *
CHPL_HWLOC: bundled
CHPL_RE2: bundled *
CHPL_LLVM: system *
CHPL_AUX_FILESYS: none
  • Back-end compiler and version, e.g. gcc --version or clang --version: none of them are on my PATH, but I'm using Clang 14.