[cfe-dev] clang doesn't know about it's installation prefix when searching header files

Holger Schurig hs4233 at mail.mn-solutions.de
Fri May 30 04:47:23 PDT 2008

> This is on Linux (Debian Etch). Maybe
> llvm::sys::Path::GetMainExecutable is buggy here?

It is indeed buggy. This

  llvm::sys::Path MainExecutablePath =
+ fprintf(stderr, "MainExecutablePath %s\n", MainExecutablePath.c_str());

says that MainExecutablePath just contains "clang". But on the
shell, it says otherwise:

  $ which clang

Unfortunately, my shell (bash) doesn't call the program in a way
so that this can be re-used. A simple test program reveals this:

  #include <stdio.h>
  int main(int argc, char *argv[])
        printf("argv[0] %s\n", argv[0]);
        return 0;

and run it like this:

  $ ./argc
  argv[0] ./argc
  $ mv argc /usr/src/llmv/dist/bin
  $ which argc
  $ argc
  argv[0] argc

... I see that using argv[0] is not sufficient, at least not if
bash 3.1.17 handles the PATH.

Only when I specify the full path does argv[] work:

  $ /usr/src/llvm/dist/bin/argc
  argv[0] /usr/src/llvm/dist/bin/argc

So, should I amend llvm::sys::Path::GetMainExecutable so that it:

* check if there is a "/" in the path?
* if not, iterate over env['PATH'] to search for itself and
  use the first match?

More information about the cfe-dev mailing list