Saw the <execution> header on cppreference, and wanted to try it out.
Here's what I've tried so far:
brew install cmake --HEAD
brew install llvm
Installed versions:
$ /usr/local/opt/llvm/bin/clang++ --version
clang version 7.0.0 (tags/RELEASE_700/final)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
$ cmake --version
cmake version 3.13.20181204-gb8db7
I thought I might have got cmake flags wrong, so tried compiling directly; here's an isolated one-liner that should work:
CPPFLAGS="-I/usr/local/opt/llvm/include" LDFLAGS="-L/usr/local/opt/llvm/lib" /usr/local/opt/llvm/bin/clang++ -std=c++17 foo.cpp
And here's the (stubborn!) error I keep getting:
fatal error: 'execution' file not found
The line it's complaining about: #include <execution>
Any clues are much appreciated!
Edit: I see the header is missing from /usr/local/opt/llvm/include/c++, so of course it can't work with what I have (and doesn't seem to be present within experimental either), is there another recommended way to install this on osx?
To answer my own question:
I was missing an explicit -std=c++17 flag (interestingly, -std=c++2a doesn't work! Which may be okay, but a bit surprising if you expect that mode to be a superset of the c++17 mode)
Anyway, I can confirm that the following works for me just fine:
CPPFLAGS="-I/usr/local/opt/llvm/include" \
LDFLAGS="-L/usr/local/opt/llvm/lib" \
/usr/local/opt/llvm/bin/clang++ \
-std=c++17 \
foo.cpp
Related
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)
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
I recently upgraded my Mac OSX from Yosemite to El Capitan and updated Xcode to v7.1. After the upgrades, I found that my C++ application no longer compiles due to a header file that cannot be found:
../../src/dir/sysArea.h:39:10: fatal error: 'boost/thread/tss.hpp' file not found
#include <boost/thread/tss.hpp>
The clang invocation is like this:
clang -g -std=c++11 -fno-inline -Wall -Werror -Wextra -D_LARGEFILE_SOURCE \
-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c \
-o ARCH.darwin_15_i86/debug/file.o file.cpp
I searched my Macintosh using the finder and the file tss.hpp no longer appears to be present. How do I port my application to El Capitan, what is the replacement of Boost's tss.hpp? I tried updating my Boost version from the prior v1.53 to the latest v1.58, but it had no impact, I get the same error when compiling.
export PATH=/usr/local/bin:$PATH
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
sudo chmod o+w /usr/local/opt /usr/local/include /usr/local/lib
brew unlink boost
brew install boost
sudo chmod o-w /usr/local/opt /usr/local/include /usr/local/lib
My C++03 application is including tss.hpp so that it can use the thread_specific_ptr<> feature:
static boost::thread_specific_ptr<Botan::AutoSeeded_RNG> _rng;
for thread local storage (e.g. each thread gets its own version of the static variable.)
The finder was not searching everywhere (would be nice if it did), I do have tss.hpp under /usr/local/include.
I tried adding -stdlib=libc++ and -stdlib=libstdc++ to the clang invocation, but neither got the complier to look in /usr/local/include for the Boost headers. What compiler flags will instruct it to look there other than hardcoding -I/user/local/include?
Note that clang says thread_local is not available as discussed here.
Doing xcode-select --install as per this answer, seems to have told clang to look in the /usr/local/include directory for headers and resolves the issue.
My OS is OS X 10.10.2 and the default compiler for C is clang.
But this version of clang does not support ubsan (undefined sanitizer) which comes in the 3.4 release of clang. I also want to use KLEE to do some analysis. AFAIK KLEE works well with LLVM-<=3.4. I decided to install
llvm-3.4 and clang-3.4 in my laptop.
After installing clang-3.4 in my system, I encountered a issue that the compiler can not locate the c++ header file. I installed clang-3.4 in /usr/local and I can find the c++ header file in /usr/local/include/c++/4.8.4. How can I add this directory to the search path of clang-3.4 and also the c++ library?
for the following demo code:
#include <iostream>
using namespace std;
int main(){
cout<<"Hellow World\n";
return 0;
}
When I compile it using command clang++ test.cpp, I got the error
test1.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^
1 error generated.
Below is the version of clang I used
clang version 3.4 (tags/RELEASE_34/final)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
I used the following shell command to install llvm-3.4 and clang-3.4:
wget http://llvm.org/releases/3.4/llvm-3.4.src.tar.gz \
http://llvm.org/releases/3.4/clang-3.4.src.tar.gz \
http://llvm.org/releases/3.4/clang-tools-extra-3.4.src.tar.gz \
http://llvm.org/releases/3.4/compiler-rt-3.4.src.tar.gz
tar zxf llvm-3.4.src.tar.gz
tar zxf clang-3.4.src.tar.gz -C llvm-3.4/tools
mv llvm-3.4/tools/clang{-3.4,}
tar zxf clang-tools-extra-3.4.src.tar.gz -C llvm-3.4/tools/clang/tools
mv llvm-3.4/tools/clang/tools/{clang-tools-extra-3.4,extra}
tar zxf compiler-rt-3.4.src.tar.gz -C llvm-3.4/projects
mv llvm-3.4/projects/compiler-rt{-3.4,}
cd llvm-3.4
./configure --enable-cxx11 \
--enable-bindings=none --enable-shared \
--enable-debug-symbols --enable-optimized
make
make install
Now I have two versions of clang in my OS, one is the default one shipped with OSX located in /usr/bin and the other is clang-3.4 located in /usr/local/bin. The previous one can find the C++ header file while the latter can not.
Did you read the user documentation of clang notably the section on command line options ? BTW, current (march 2015) version of clang is 3.6!
For C++ code you should use the clang++ command, not the clang command.
You might pass -I and -L options to clang++ but you might perhaps have misinstalled your clang compiler.
You should be aware of the -v and -H options of clang or clang++ ; they could be useful, at least to understand more your issue.
addenda
BTW, a program reported to work with Clang 3.4 is extremely likely to work with a more modern version, like Clang 3.5 or 3.6
You probably have a PATH issue; you should have configure -d your Clang-3.4 & LLvm-3.4 programs with --program-suffix=-my-3.4 (if you do that, repeat your entire compiler build and installation) and you probably should run /usr/local/bin/clang++-my-3.4 ; maybe you also need some --with-gcc-toolchain additional configure option.
I'm pretty sure that you should be able to try to compile or use your mysterious software requiring Clang-3.4 with a more modern version like 3.5 or 3.6 ; your MacOSX 10.10.2 is rumored to have a Clang-3.5 based system compiler, it very probably is able to compile and work with your mysterious software.
I have the following file foo.cpp:
#include <vector>
struct MyClass
{
std::vector<int> v;
};
It can be successfully compiled with clang (I'm using clang 3.3 on Ubuntu 13.04 32bit):
clang++ -c foo.cpp
Now I want to print AST:
clang++ -cc1 -ast-print foo.cpp
and I've got the following error
foo.cpp:1:10: fatal error: 'vector' file not found
#include <vector>
^
struct MyClass {
};
1 error generated.
It looks like clang++ -cc1 doesn't know about system include files etc.
I'm wondering how to set up includes for clang++ -cc1?
You need to set up the right include paths.
on my system I added
-I/usr/include/i386-linux-gnu/c++/4.8 -I/usr/include/c++/4.8
to the compiler flags. The first one was so that it could find
bits/c++config.h
Of course the 4.8 is due to the fact I am using a compiler compatible with g++-4.8
I also added
-std=c++11 -stdlib=libstdc++
as compiler options.
Hope this helps
It's a Frequently Asked Question
#john is correct. For posterity, the relevant portions of the FAQ are (with names tweaked to match the question) :
clang -cc1 is the frontend, clang is the driver. The driver invokes the frontend with options appropriate for your system. To see these options, run:
$ clang++ -### -c foo.cpp
Some clang command line options are driver-only options, some are frontend-only options. Frontend-only options are intended to be used only by clang developers. Users should not run clang -cc1 directly, because -cc1 options are not guaranteed to be stable.
If you want to use a frontend-only option (“a -cc1 option”), for example -ast-dump, then you need to take the clang -cc1 line generated by the driver and add the option you need. Alternatively, you can run clang -Xclang <option> ... to force the driver [to] pass <option> to clang -cc1.
I did the latter (-Xclang) for emitting precompiled headers:
/usr/bin/clang++ -x c++-header foo.hpp -Xclang -emit-pch -o foo.hpp.pch <other options>
^^^^^^^
Without the -Xclang, clang++ ignored the -emit-pch. When I tried -cc1, I had the same problem as the OP — clang++ accepted -emit-pch but didn't have the other options the driver normally provides.