I installed llvm and clang 3.9 along with all the other packages using the below command as given in LLVM Nightly packages link.
sudo apt-get install clang-3.9 clang-3.9-doc llvm-3.9 llvm-3.9-dev llvm-3.9-doc llvm-3.9-examples llvm-3.9-runtime clang-format-3.9 python-clang-3.9 libclang-common-3.9-dev libclang-3.9-dev libclang1-3.9 libclang1-3.9-dbg libllvm-3.9-ocaml-dev libllvm3.9 libllvm3.9-dbg lldb-3.9 lldb-3.9-dev liblldb-3.9-dbg
Then I tried to compile and run the sample lexer and parser for kaleidoscope language according to this tutorial.
However, I am not able to compile the given sample program, because I get the error:
clang++-3.9 -g -O3 toy.cpp
toy.cpp:1:10: fatal error: 'llvm/ADT/STLExtras.h' file not found
#include "llvm/ADT/STLExtras.h"
^
1 error generated.
I think this error is because LLVM was installed as llvm-3.9 and hence all the files were installed in directories ending with *-3.9. How can I fix this error without having to remove the installation and do a manual build install from the LLVM source?
That looks like a bug in the tutorial -- the code in toy.cpp used to be self-contained, but it now depends on an LLVM header (this is a recent change).
You can use the command provided in chapter 3 to build instead, i.e.:
clang++ -g -O3 toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core` -o toy
Related
I am trying to install Armadillo with Homebrew with
brew install armadillo
but when I try to compile with
g++ example.cpp -o example -std=c++11 -O2 -larmadillo
it gives the following error:
fatal error: 'armadillo' file not found
How can I solve this problem?
I'm guessing here that you have a new M1 Mac. The issue in this case is that ARM-native homebrew is installed to /opt/homebrew/ by default, meaning armadillo was installed to /opt/homebrew/include/ which is not in your search path.
To see if this is the case, try providing the paths as follows:
CPATH=/opt/homebrew/include LIBRARY_PATH=/opt/homebrew/lib g++ example.cpp -o example -std=c++11 -O2 -larmadillo
To avoid the issue in general, I'm running with those CPATH and LIBRARY_PATH variables exported in my ~/.zprofile file (using zsh). I found this answer on the apple stack exchange helpful.
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)
Having installed LLVM on Ubuntu 16.04 using the command:
sudo apt-get install clang llvm
I get the following error when compiling:
nlykkei#nlykkei-VirtualBox:~$ clang++ -g toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs` -o toy
warning: unknown warning option '-Wno-maybe-uninitialized'; did you mean
'-Wno-uninitialized'? [-Wunknown-warning-option]
1 warning generated.
To be specific, I follow the tutorial: http://llvm.org/docs/tutorial/LangImpl03.html on the LLVM website.
The version of LLVM is 3.8.
How do I get rid of this warning?
Thanks.
This is a bug in llvm-config. Long story short, llvm-config outputs -Wno-maybe-uninitialized which is not a warning implemented by clang.
One possible workaround is to add an extra flag squelching warnings about unknown warnings.
clang++ <your flags> -Wno-unknown-warning-option `llvm-config ...`
This warning comes when you recently upgraded your sdk-build-tools with 30.x
I resolved the issue by downgrading sdk-build-tools by 29.x.
Delete all the intermediate files , they will be auto generate again.
Clean Project .
Invalidate Cashes and Restart the Project.
Woow, warning has been removed now.
Answer mentioned here https://github.com/envoyproxy/envoy/issues/18986 might help. Mostly changing Wno-maybe-uninitialized with -Wno-uninitialized in / bazel/envoy_internal.bzl
I have been working through the Kaleidoscope tutorial for LLVM and have been having endless problems compiling it. In the following tutorial it appears that the flag "--system-libs" doesn't exist for llvm-config (it simply prints out a usage block). I have tried leaving it out but it seems like a rabbit hole of linker errors which leads me to believe I have just set up my development environment completely wrong. I have tried it both on OSX Yosemite and Ubuntu with similar results. The not found error can be resolved by adding -I [path to llvm] however this just exposes more errors making me think that is the wrong approach.
http://llvm.org/releases/3.6.0/docs/tutorial/LangImpl3.html
$make
#clang++ -g -v -L -std=c++11 -O3 toy.cpp -I/usr/include/llvm-3.5/ `llvm-config --cxxflags --ldflags --libs all` -o toy
clang++ -g -O3 toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core` -o toy
usage: llvm-config <OPTION>... [<COMPONENT>...]
Get various configuration information needed to compile programs which use
LLVM. Typically called from 'configure' scripts. Examples:
llvm-config --cxxflags
llvm-config --ldflags
llvm-config --libs engine bcreader scalaropts
Options:
--version Print LLVM version.
--prefix Print the installation prefix.
--src-root Print the source root LLVM was built from.
--obj-root Print the object root used to build LLVM.
--bindir Directory containing LLVM executables.
--includedir Directory containing LLVM headers.
--libdir Directory containing LLVM libraries.
--cppflags C preprocessor flags for files that include LLVM headers.
--cflags C compiler flags for files that include LLVM headers.
--cxxflags C++ compiler flags for files that include LLVM headers.
--ldflags Print Linker flags.
--libs Libraries needed to link against LLVM components.
--libnames Bare library names for in-tree builds.
--libfiles Fully qualified library filenames for makefile depends.
--components List of all possible components.
--targets-built List of all targets currently built.
--host-target Target triple used to configure LLVM.
--build-mode Print build mode of LLVM tree (e.g. Debug or Release).
Typical components:
all All LLVM libraries (default).
engine Either a native JIT or a bitcode interpreter.
toy.cpp:1:10: fatal error: 'llvm/IR/Verifier.h' file not found
#include "llvm/IR/Verifier.h"
^
1 error generated.
make: *** [parser] Error 1
Turns out the version of llvm-config I am using is out of date. On Ubuntu I can just apt-get install llvm-config-3.6 and on OSX I can do a brew install homebrew/versions/llvm36. Finally use llvm-config-3.6 instead of just llvm-config.
I would like to install boost with specified compilers, such as the gcc-4.9.1 that I have installed in <gcc_49_root>. The current OS is Mac OS X 10.9.4, but I would like this installation process to work on other OS. The documentation of boost is quite opaque about this scenario. What I have tried is as following:
$ ./bootstrap.sh
-n Building Boost.Build engine with toolset darwin...
tools/build/src/engine/bin.macosxx86_64/b2
-n Detecting Python version...
2.7
-n Detecting Python root...
/System/Library/Frameworks/Python.framework/Versions/2.7
-n Unicode/ICU support for Boost.Regex?...
not found.
Generating Boost.Build configuration in project-config.jam...
Insert using gcc : 4.9.1 : <gcc_49_root>/bin/g++-4.9 : ; into project-config.jam.
$ ./b2 --prefix=<...> toolset=gcc-4.9.1 install
But encountered the errors:
Jamfile</Users/dongli/Shares/works/packman/test/packages/Boost/boost_1_56_0/libs/context/build>.gas64 bin.v2/libs/context/build/gcc-4.9.1/release/address-model-64/architecture-x86/threading-multi/asm/make_x86_64_sysv_macho_gas.o
FATAL:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../libexec/as/x86_64/as: I don't understand '-' flag!
clang: error: no input files
cpp -x assembler-with-cpp "libs/context/src/asm/make_x86_64_sysv_macho_gas.S" | as --64 -o "bin.v2/libs/context/build/gcc-4.9.1/release/address-model-64/architecture-x86/threading-multi/asm/make_x86_64_sysv_macho_gas.o"
...failed Jamfile</Users/dongli/Shares/works/packman/test/packages/Boost/boost_1_56_0/libs/context/build>.gas64 bin.v2/libs/context/build/gcc-4.9.1/release/address-model-64/architecture-x86/threading-multi/asm/make_x86_64_sysv_macho_gas.o...
gcc.link.dll bin.v2/libs/atomic/build/gcc-4.9.1/release/threading-multi/libboost_atomic.dylib
ld: unknown option: -h
collect2: error: ld returned 1 exit status
"/usr/local/opt/gcc/bin/g++-4.9" -o "bin.v2/libs/atomic/build/gcc-4.9.1/release/threading-multi/libboost_atomic.dylib" -Wl,-h -Wl,libboost_atomic.dylib -shared -Wl,--start-group "bin.v2/libs/atomic/build/gcc-4.9.1/release/threading-multi/lockpool.o" -Wl,-Bstatic -Wl,-Bdynamic -Wl,--end-group
...failed gcc.link.dll bin.v2/libs/atomic/build/gcc-4.9.1/release/threading-multi/libboost_atomic.dylib...
What should I do with these errors? Thanks in advance!
Apple's linker ld(ld64) is different from other UNIX/GNU linkers and does not support some options, such as -h(soname), --start-group, --end-group, etc,. Those errors you got("unknown option") were the results of trying to pass non-supported flags to Apple's ld when you specify the gcc toolset.
The way I hacked mine was to first include "darwin" in the project config file:
using gcc : 4.9.1 : <gcc_49_root>/bin/g++-4.9 : <linker-type>darwin ;
Next removing the non-supported flags from {BOOST_DIR}/tools/build/src/tools/gcc.jam, from the long command in the "actions link.dll bind LIBRARIES" block:
remove/comment out this portion:
... $(HAVE_SONAME)-Wl,$(SONAME_OPTION)$(SPACE)-Wl,$(<[-1]:D=) ...
Afterwards the Boost libraries built without errors and worked fine in other gcc4.9 compiled codes.
$ ./bootstrap.sh --with-toolset=gcc
$ ./b2 --toolset=gcc-4.9.1
UPDATE (May 2015): I recently did a new built of gcc 5.1.0 and Boost 1.58.0 on Yosemite (10.10.1). Same fix worked for me.
I am using Mac Yosemite and this worked for me.
Open "tools/build/example/user-config.jam" and change
# Configure gcc (default version).
# using gcc ;
# Configure specific gcc version, giving alternative name to use.
using darwin : 5 : g++-5 ;
Then open "tools/build/src/tools/darwin.jam" then delete below line (this step may not be required. just try both way);
"$(CONFIG_COMMAND)" -dynamiclib -Wl,-single_module -install_name "$(<:B)$(<:S)" -L"$(LINKPATH)" -o "$(<)" "$(>)" "$(LIBRARIES)" -l$(FINDLIBS-SA) -l$(FINDLIBS-ST) $(FRAMEWORK_PATH) -framework$(_)$(FRAMEWORK:D=:S=) $(OPTIONS) $(USER_OPTIONS)
As last step, compile and install
$ ./bootstrap.sh --with-libraries=all --with-toolset=darwin --prefix=/usr/local/boost_for_gcc
$ ./b2
$ ./b2 install
Now you can compile your code like below
$ g++ -o main main.cpp -L/usr/local/boost_for_gcc/lib -I/usr/local/boost_for_gcc/include -lboost_regex
Reference:
http://qiita.com/misho/items/0c0b3ca25bb8f62aa681