I'm trying to make a compiler and I'm using llvm (C++ api) for intermediate and final code production. Though when trying to execute the command:
llvm.o: llvm.cpp llvm.h
$(CPP) llvm.cpp -c -$(FLAGS)
in my make file I'm getting the error:
In file included from llvm.cpp:6:
./opt.h:5:10: fatal error: 'llvm/IR/Constants.h' file not found
#include <llvm/IR/Constants.h>
^~~~~~~~~~~~~~~~~~~~~
1 error generated.
I'm using Mac Os (Sierra version 10.12.6) and I've installed llvm using brew (brew install llvm
) so I can't understand how the library file can't be found.
Also my clang version:
bash-3.2$ clang --version
Apple LLVM version 9.0.0 (clang-900.0.37)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
I've googled it a lot but couldn't find anything that solve my problem, any help appreciated !!!.
What're your FLAGS? You would need to provide linker flags and header search flags.
The following could help you:
llvm.o: llvm.cpp llvm.h
$(CPP) llvm.cpp -c -$(FLAGS) `llvm-config --cxxflags --ldflags --libs`
Note that the --libs
without any parameters will link your binary with all the LLVM libraries.
UPD:
On MacOS llvm-config and other tools are not added to the $PATH
, because it would override system compiler and can screw your system in some way. You would need to use the full path, e.g. /usr/local/Cellar/llvm/3.9.0/bin/llvm-config
. Make sure you use the right version here.
Also, make sure that your FLAGS are actually evaluated and not pasted to the command as is:
FLAGS=$(shell llvm-config --cxxflags --ldflags --libs)