Clang : Failed to find C++11 headers - c++

I am trying to build all the examples in the Crow library with clang 3.6 and I can see the CC/CXX has been found properly by using clang 3.6. It uses cmake which I am not quite familiar with.
However it failed to find C++11 headers.
Error is like:
'future' file not found
It seems that the libstdc++ is not specified properly, or some people reckon it needs to build the clang libstdc++ myself.
Anyone can shed some light on this will be much appreciated.

So based on the previous comment the issue is that you don't enable the C++ 11 mode in Clang.
As in referenced question, the issue is simply that you do not say to Clang (or in future for GCC) to look for C++ headers.
"Clang's command line is gcc-compatible so you have to enable C++11 support via the followinf command-line switch"
-std=c++11
If after this you all you have to do is to write your C++ 11 code. If you use Makefiles you should add to your CXX arguments the command line switch to Clang.

Related

Problem with using clang as compiler for code::blocks

I installed llvm for clang, because I wanted to use clang for code::blocks as compiler, since I need compiler that supports c++20, so I installed llvm, the bin was added in environmental variables, even the code::blocks detected llvm as compiler, however I get error when i want to compile my code:
-------------- Build file: "no target" in "no project" (compiler: unknown)---------------
clang++.exe -c C:\Users\Temirlan\labs\lab4\rpn.cpp -o C:\Users\Temirlan\labs\lab4\rpn.o
clang++.exe -o C:\Users\Temirlan\labs\lab4\rpn.exe C:\Users\Temirlan\labs\lab4\rpn.o
C:\Users\Temirlan\labs\lab4\rpn.cpp:180:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
Do you know what is the problem or maybe the picture will help?
photo of compiler executables in code::blocks
I got error of "fatal error: 'iostream' file not found"
All modern compilers support C++20 (to slightly varying extent): both Clang, GCC, and MSVC. So this shouldn't affect your choice (but I do think that Clang is the best option).
Clang can be set up in different ways: (in order of personal preference)
With GCC's standard C++ library, libstdc++. Install MSYS2, then use it to install both Clang and GCC: pacman -S mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-clang. Then use C:/msys64/ucrt64/bin/clang++.exe as the compiler. (There's also MINGW64 variant instead of UCRT64, read about the difference here).
With its own standard C++ library, libc++. Install MSYS2, then use it to install libc++-flavored Clang: pacman -S mingw-w64-clang-x86_64-clang. Then use C:/msys64/clang64/bin/clang++.exe as the compiler.
With MSVC's standard C++ library, aka MSVC STL. Install the official Clang build, and install Visual Studio.
Note that the first two options don't involve downloading the official Clang build. The official build wants the MSVC STL by default, which you don't have, since you didn't install VS. (And if you do install it, you might as well use it instead of CodeBlocks.)
The official Clang build can be made to work with other standard libraries, but they need to be installed separately, and you need to persuade it with some compiler flags. It's easier to install the MSYS2's version, which already uses the correct flags by default.

How to set Xcode up for LLVM/Clang development?

I've installed LLVM and Clang on macOS Sierra.
Until now, I've used the llvm-config command for compiling with clang. This works fine, and I can compile and link the LLVM tutorial programs from the command-line.
However, I'd like a professional IDE for development with type-checking and proper debugging.
The problem is that I don't know how to set Xcode up for LLVM/Clang development...
I include the C++ headers in the include/llvm directory, and I think I pass the libraries to the linker, but something goes wrong:
In the compilation phase, I get a linker error saying, e.g, that symbol parseIRFile isn't found. However, the IDE can see the functions in the header files.
Would someone help me out in setting up Xcode for LLVM/Clang development? I'm new to macOS and Xcode, so please give clear explanations of the required steps.
Thanks very much.

How to use std::thread of C++ 11 under Cygwin GCC 4.7.2

I've been trying to compile a multithread hello-world program under Cygwin using the newly introduced C++ 11 std::thread feature without success. I compiled and installed GCC 4.7.2 by myself, and the same code works without any problems under Linux with the same version of GCC. The first error I got was that the compiler did not recognize the -pthread flag. After researching on it for a while I noticed someone said on Cygwin this flag should be -lthread. I made the change and that error was gone, but another series of errors occur telling me thread is not member of std. I wonder if it's caused by the wrong configuration of the compiler during installation, or std::thread is simply not supported under Cygwin?
This looks like you did not compile the program with the appropriate standard library flag. If you want to compile for C++11 you should use:
g++ --std=c++0x -o ...
The --std flag sets the appropriate language compatibility level. If this does not help, please post the error messages you got as a source listing.

Trouble Building Trilinos (Scientific Computation Library) on Mac OS X

I am trying to build the Trilinos library on Mac OS X 10.6.8, basically following the instructions on this page and the CMake Quickstart document included with Trilinos.
In order to build it with CMake, the instructions recommend setting up a directory, e.g. /usr/local/trilinos, creating a ./do-configure script in it and running it. My script is:
EXTRA_ARGS=$#
cmake \
-D CMAKE_BUILD_TYPE:STRING=DEBUG \
-D Trilinos_ENABLE_TESTS:BOOL=ON \
$EXTRA_ARGS \
${TRILINOS_HOME}
Running this script starts the configuration, until an error appears. The verbose output can be found here: http://pastebin.com/abrEghD7
I think the relevant part of the message is:
-- Verifying Fortran/CXX Compiler Compatibility - Failed
CMake Error at /usr/local/Cellar/cmake/2.8.7/share/cmake/Modules/FortranCInterface.cmake:284 (message):
The Fortran compiler:
/usr/local/bin/gfortran
and the CXX compiler:
/usr/bin/c++
failed to compile a simple test project using both languages. The output
was:
However, I cannot explain why the script blames the Fortran and C++ compilers. I have tested the Fortran compiler with "Hello World", and used the C++ compiler of OS X for entire projects. As far as I can tell, both compilers work properly.
Can anyone guess what might be wrong?
EDIT: Seems like it is some compatibility issue, not a problem with the indivual compilers.
When I compile paraview. I set my CXX compiler to g++ and not the standard c++ as cmake does. Because otherwise I see a similar error.
Where did you get gfortran from? Builds from most sources don't support mac specific extensions like -arch which might make problems trying to combine both of them. Or they might just be different versions (if you're gfortran is much newer than your g++ they might be trying to pull in incompatible runtime versions).
In the numerical python community (which depends a lot on fortran) the recommended source for OS X is the binary from here. This is matched to the XCode gcc version and supports the Mac specific extensions.

is there any way to configure waf to build c++ program in mac os?

I just suffer a problem that the all the things works well on my ubuntu.
However, I want to get things work on my mac, bad thing happens.
it shows the following errors
cc1plus: error: unrecognized command line option "-std=c++0x"
I am total new to mac stuff, I got the xcode 4 installed.
I guess there must be c++0x, but I wonder how can i configure it with waf.
Thanks a lot!!
I’m guessing you’re using GCC supplied with Xcode. That’d be GCC 4.2.1, a rather old version that won’t be updated by Apple in the foreseeable future.
You have essentially two options:
Xcode ships Clang/LLVM besides GCC, so you could use Clang/LLVM instead. That -std=c++0x option is recognised by Clang/LLVM but C++0x is not as fully supported as in recent versions of GCC. The LLVM project keeps a page listing their current C++0x support status.
Use a more recent version of GCC. You can either compile it locally or install it via one the open source package managers available on Mac OS X: MacPorts, Fink, Homebrew. I don’t really know if and which versions of GCC they’re able to build, so check with them first.
As Xcode comes with Clang on mac you can get c++0x support if you configure waf to use Clang.
In your wscript add to configure:
def configure( conf ):
...
conf.env.CXXFLAGS = [ '-std=c++0x', '-stdlib=libc++' ]
conf.env.LINKFLAGS = [ '-std=c++0x', '-stdlib=libc++' ]
....
Then run waf as:
CXX=clang++ waf configure
CXX=clang++ waf build
On Mac you can't go wrong with clang. You'll have to build the compiler yourself (using e.g. gcc-4.2 that you already have). It has -std=c++0x. The support for it isn't complete, but it is growing all the time. On the Mac you might also look at libc++ for C++0x support (combined with clang).