0

I downloaded LLVM (12.0.1) from the script file llvm.sh which they have now started to include on their Debian downloads page.

Ran clang and everything was working as expected(good job dev team I guess?).

The installation script installed LLVM in /usr/lib/LLVM-12/ and /usr/include/LLVM-12/ (these had some .h files)

So I tried writing some passes; created an out-of-tree build using the answer given here: Facing issue with makefile for Hello pass in llvm

But when I ran the make, it gave me this error:

/usr/include/llvm-12/llvm/Pass.h:337:10: fatal error: llvm/PassAnalysisSupport.h: No file or directory
337 | #include "llvm/PassAnalysisSupport.h"
    |
compilation terminated.

So I checked /usr/include/llvm-12/llvm/ and found that Pass.h and PassAnalysisSupport.h both were present in the current directory, so shouldn't the Pass.h file have #include "PassAnalysisSupport.h" instead of the present #include "llvm/PassAnalysisSupport.h"?

I also checked the code for Pass.h online and it also had #include "llvm/PassAnalysisSupport.h". Other header files in the llvm directory also used the same format #include "llvm/<name>"

So what is going on here, who messed up, the devs or my llvm.sh (also the devs) or the problem is something else?

Any help would be appreciated (Im using Mint MATE 20.2 if thats relevant)

Source file (headers; firstpass/first/fpass.cpp):

#include <llvm-12/llvm/Pass.h>
#include <llvm-12/llvm/IR/Function.h>
#include <llvm-12/llvm/Support/raw_ostream.h>
#include <llvm-12/llvm/IR/LegacyPassManager.h>
#include <llvm-12/llvm/Transforms/IPO/PassManagerBuilder.h>

(firstpass/CMakeLists.txt):

find_package(LLVM REQUIRED CONFIG)
include_directories($(LLVM_INCLUDE_DIRS))

add_subdirectory(first)

(firstpass/first/CMakeLists.txt):

add_library(LLVMfirst MODULE fpass.cpp)
Tony
  • 81
  • 9
  • Post your full CMakeLists.txt and some minimal example code (just a source file including the problematic header is likely enough). – Alex Reinking Jan 27 '22 at 00:33
  • Edited the question. – Tony Jan 27 '22 at 07:03
  • One work around I can think of instead of building from source now is create a link to the directory itself basically `ln -s . llvm`. But thats also too much work. – Tony Jan 27 '22 at 07:24
  • 1
    Your includes should definitely be `#include `, without the `llvm-12` prefix. Also, does this answer your question? https://stackoverflow.com/a/70844274/2137996 – Alex Reinking Feb 01 '22 at 07:20
  • @AlexReinking It worked when I removed `llvm-12` from the headers. But my `/usr/include/` contains `llvm-12` and `llvm-c-12` only and my `/usr/local/include/` is empty so from where is it searching and getting the `llvm` directory? – Tony Feb 01 '22 at 17:33
  • Well, `include_directories($(LLVM_INCLUDE_DIRS))` is going to add `/usr/include/llvm-12` as a `-I` flag, so headers will be searched in that directory. However, you _really_ should not use `include_directories`, ever. Look at the answer I linked for an example how to actually link to libraries in CMake. – Alex Reinking Feb 01 '22 at 17:59
  • 1
    For understanding llvm passes and out-of-tree cmake builts I suggest you to scrutinize this github repository: https://github.com/banach-space/llvm-tutor – Celuk Feb 03 '22 at 08:17
  • @Celuk Thats helpful thanks a lot. – Tony Feb 04 '22 at 09:09

0 Answers0