error: <atomic> is not implemented in LLVM version 5.1 - c++11

I'm trying to compile libcxxabi with cmake, and running into issues. I believe that this is because I don't have a separate copy of llvm installed that has llvm-config. So I've checked out llvm, and am trying to build that with cmake. I get the error:
CMake Error at cmake/modules/HandleLLVMOptions.cmake:37 (message):
Host Clang must be able to find libstdc++4.7 or newer!
And cmake/modules/HandleLLVMOptions.cmake:37 is literally a block like:
check_cxx_source_compiles("
#include <atomic>
std::atomic<float> x(0.0f);
int main() { return (float)x; }"
LLVM_NO_OLD_LIBSTDCXX)
if(NOT LLVM_NO_OLD_LIBSTDCXX)
message(FATAL_ERROR "Host Clang must be able to find libstdc++4.7 or newer!")
endif()
and if I try to compile the 3 liner with the compiler flag -std=c++0x (which is higher up in the cmake file) I get the error:
atomic.cpp:1:10: fatal error: 'atomic' file not found
#include <atomic>
^
1 error generated.
How is it that I don't have support for c++11 atomics? I'm running OSX 10.8.5, upgraded from 10.8.4, and XCode version 5.1.1, and clang++ 5.1 (clang-503.0.40) (based on LLVM 3.4svn). I have no options to upgrade xcode in the app store, nor the developer tools. Do I need to reinstall XCode, or upgrade to Mavericks?

I needed to check out all of LLVM and pass an additonal command line argument to CMake.
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
cd ../projects
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
cd ..
mkdir build
cd build
cmake .. -DLLVM_ENABLE_LIBCXX=ON
make
make install

Had the same issue with xCode 6.4. When using atomic in a simple helloWorld program it worked, but when using a project generated by CMake, I had the "#error is not implemented"
It appears CMake needs special flags to enable c++11 on mac... So, did exactly (almost... replaced if(UNIX) by if(APPLE)) as kitware indicates here:
https://cmake.org/Wiki/CMake/Tutorials/C%2B%2B11Flags
In case the link stops working one day....
cmake_minimum_required(VERSION 2.6)
PROJECT(Test)
if(UNIX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=gnu++0x")
endif()
# MSVC does not require any special flags

Related

Qtcreator on Mac OS can't see std when using cmake and openmp

If I have a project with this CMakeLists.txt
cmake_minimum_required(VERSION 3.18)
project(myproject LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(myexe main.cpp)
find_package(OpenMP REQUIRED)
target_link_libraries(myexe PUBLIC OpenMP::OpenMP_CXX)
And the following code in main.cpp
#include <iostream>
int main ()
{
std::cout << "Hi\n";
}
The project actually builds and runs just fine. But the IDE itself is broken and can't find the std headers. And as a result it has red squiggly lines under everything std related. In our example it will look like this:
This issue only happens when I use OpenMP in CMakeLists.txt
In the "General Messages" tab I'm getting the following error:
Compiler feature detection failure!
The command "/usr/bin/clang++ -fPIE -fopenmp -std=gnu++17 -x c++ -E -v - -target x86_64-apple-darwin20.3.0" terminated with exit code 1.
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1"
clang: error: unsupported option '-fopenmp'
So I'm pretty sure that's related. How do I fix this? Halp!
Ok, I don't understand what causes that issue but I figured out how to solve it.
We'll have to use the llvm clang.
brew install llvm
That will install clang and clang++ compilers at /usr/local/opt/llvm/bin/.
We'll have to make sure that qtcreator uses the llvm compiler instead of the one at /usr/bin/clang++. And we do that by making a new kit that uses the new compiler and configure the project to use that new kit instead.
Qtcreator > Preferences > Kits > Compilers
Add > Clang > C
Give it a some name like: llvm clang, and its path at /usr/local/opt/llvm/bin/clang
Add > Clang > C++
Give it a some name like: llvm clang++, and its path at /usr/local/opt/llvm/bin/clang++
Qtcreator > Preferences > Kits > Kits
Add
Give it a some name like: llvm clang, and choose the llvm clang and llvm clang++ for the C and C++ compilers respectively.
And the last step would be to have your project use the new kit instead.
On the Projects tab on the left side
Build & Run
Choose the llvm clang kit
And that will be all! Hope that helps :)

omp.h not found, OS X Yosemite not using newest gcc version

I am trying to build GraphChi on OS X Yosemite but get the following error:
fatal error: 'omp.h' file not found
From this question - How to include omp.h in OS X? - I learned that Yosemite uses Clang instead of gcc, which does not include omp.h.
$ which gcc
/usr/bin/gcc
$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
Next, I installed gcc via Homebrew
$ brew info gcc
gcc: stable 4.9.2 (bottled)
http://gcc.gnu.org
/usr/local/Cellar/gcc/4.9.2_1 (1092 files, 177M)
Built from source with: --without-multilib
and updated $PATH to include the path to the new gcc version
$ echo $PATH
/usr/local/Cellar/gcc/4.9.2_1:usr/local/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
however, gcc -v and which gcc still point to the old version, and building GraphChi still doesn't work due to the missing omp.h file
Does anyone know what else I need to do?
Update
locate omp.h returned:
/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/lib/gcc/i686-apple-darwin11/4.2.1/include/omp.h
/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.1.0/4.9.2/include/omp.h
/usr/local/Cellar/gfortran/4.8.2/gfortran/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2/include/omp.h
my ~/.profile:
export PATH=/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.1.0/4.9.2/include:/usr/local/Cellar/gcc/4.9.2_1/bin:usr/local/bin:/opt/local/bin:/opt/local/sbin:$PATH
I solved this with installing gcc with homebrew:
brew install gcc --without-multilib
and then building the source code with
CC=gcc-5 CXX=g++-5 cmake ..
CC=gcc-5 CXX=g++-5 make -j7
Once you have installed gcc-4.9 with homebrew, it will automatically be in your path. To use OpenMP, you just need to make sure you are using the newly installed gcc-4.9, and it will be able to find omp.h.
In the case of GraphChi, you will have to go change line 3 of the Makefile to be gcc-4.9. From there, running make should just work. They describe this in their README, but at least the version they describe is out of date https://github.com/GraphChi/graphchi-cpp#problems-compiling-on-mac.
clang does not support OpenMP yet. Also gcc by default links to Apple's LLVM clang compiler (not the GCC installed from brew).
Instead gcc-4.9 would link to GCC. I think if -fopenmp is specified omp.h is included automatically.
It is possible to manually build a version of clang with OpenMP support, see http://clang-omp.github.io
You shouldn't add the include path to PATH; instead, specify it as CFLAGS, including the -I option. You can export the CFLAGS variable, or set it on the fly.
Depending on how you compile things, you could do
CFLAGS=-I/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.1.0/4.9.2/include/omp.h gcc <whatever>
Of course, in this case you can specify it directly on the gcc command (as -I/usr/local/....), but the CFLAGS variable also works with configure (as configure often won't have an option to specify where it should look for specific include files); probably with make, or even for those installing a Python package: CFLAGS=-I... pip install <some-package>.
Other flags to consider are
CXXFLAGS: C++ specific pre-processor flags
LDFLAGS: linker specific flags (e.g. LDFLAGS=-L/some/path/... for linking with dynamic libraries).
CC: specify the C compiler to use. This is an easy way to avoid the built-in gcc alias for clang on OS X. Just use CC=/usr/local/bin/gcc-4 make or similar.
CXX: specify the C++ compiler to use.

qt creator defaults to g++ (4.2) after specifying custom GCC

Problem
I am having an issue implementing the g++48 compiler in QT Creator. I built this compiler using MacPorts. It appears that QT Creator ignores my compiler and defaults xcode g++42. How do I properly setup the compiler to override this?
Troubleshooting
Did you install gcc/g++ correctly and is it the main one selected?
I have ensured that gcc was installed correctly and the path is correct by doing the follows:
:~ which gcc:
/opt/local/bin/g++
:~ g++ --version:
g++ (MacPorts gcc48 4.8.1_3) 4.8.1
What system are you using?
My system: Mac OSX 10.9 Mavericks. QT Creator 2.8.1 Based on QT 5.1.0.
Toolchain setup: In QT Creator I specified the custom GCC compiler by going Compilers_Add_GCC and putting in the compiler path /opt/local/bin/g++. If I hover the mouse over any of the #include lines in *.cpp then it properly displays the path /opt/local/include/gcc48/{headerName}. I suspect the problem is related to the QT Mkspecs, but I really don't understand what this is or how to write a custom one for my custom gcc installation (if necessary). Can this be explained?
Kit updated in QT Creator? The kit was updated by following the directions that here: Qt Creator use another GCC Version located in another Place
Why do you suspect g++42 is being used? This is based on the results I get from inspecting the build log file.
12:30:19: Running steps for project untitled...
12:30:19: Configuration unchanged, skipping qmake step.
12:30:19: Starting: "/usr/bin/make"
/Applications/Xcode.app/Contents/Developer/usr/bin/g++ -c -pipe -std=c++11 -g -gdwarf-2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.6 -Wall -W -fPIE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -I/Users/raymondvaldes/Qt/5.1.0/clang_64/mkspecs/macx-g++ -I/Users/raymondvaldes/Documents/code/untitled -I. -o main.o /Users/raymondvaldes/Documents/code/untitled/main.cpp
/Users/raymondvaldes/Documents/code/untitled/main.cpp:4:10: fatal error: 'random' file not found
#include <random>
^
1 error generated.
make: *** [main.o] Error 1
12:30:20: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project untitled (kit: gcc48)
When executing step 'Make'
12:30:20: Elapsed time: 00:01.
and
RAYMONDs-MacBook-Air:~ raymondvaldes$ /Applications/Xcode.app/Contents/Developer/usr/bin/g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
Finally, here is my simple working example:
#include <iostream>
#include <complex>
#include <cmath>
#include <random>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
and my pro file.
cache()
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
QMAKE_CXXFLAGS += -std=c++11
SOURCES += main.cpp
Thank you.
I finally solved this issue and I am now able to use my MacPorts GCC48 compiler in QT Creator. As I suspected I needed to create a gcc48 mkspecs folder in the QT Directory and feed the folder name to the QT Creator custom compiler setup screen. I created "macs-g++48" folder that was copied from the generic "macs-g++" folder in "~path~QT/5.1.x/clang_64/mkspecs". I had to modify qmake.conf. I commented out
#include(../common/g++-macx.conf)
#include(g++-base.conf)
and placed their contents within quake.conf while making the following modifications:
QMAKE_CC = gcc-mp-4.8
QMAKE_CXX = g++-mp-4.8

Building Qt 4.8.1 from src on MacOS using gcc 4.5

I have a question about building Qt SDK 4.8.1 using gcc on Mac. I need to use gcc 4.5 or higher, so I installed mp-gcc45 package using macports (so tried with mp-gcc47), selected this version of gcc, so
gcc -v
Says me that gcc version 4.5.4 (MacPorts gcc45 4.5.4_6)
So I downloaded QtSDK src from official site, configure it and there is an error at first step:
cc1plus: error: unrecognized command line option "-fconstant-cfstrings"
Maybe its stupid solution, but I remove this flags from configure file, so I get a error after make call:
g++: unrecognized option '-Xarch_x86_64'
Can you give me an advice, how to build Qt using this version of gcc?
Non-Apple gcc will never work with Qt of any version. Only Apple gcc recognizes those Apple flavored compiler options.
You are stuck with gcc 4.2 on Mac. There's no way around it.

Compiler-RT CLANG LLVM

I have GCC 4.1.2 and like to build CLANG / LLVM using this GCC compiler version ony. I need source to source translation library so that I can modify my existing source code for some requirement.
Initially I faced issues regarding usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found during LLVM / CLANG make. So in downloaded and build GCC 4.5.0 and installed at a local path. I found that libstdc++.so.6 of GCC 4.5.0 has GLIBCXX_3.4.9 version. Since I wanted to compile using GCC 4.1.2 I set my dynamic library path as:
setenv LD_LIBRARY_PATH /local/gcc-4.5.0/lib64:$LD_LIBRARY_PATH
And stated the make again after 'make clean'. Now that error did not occur.
However I am facing issues while compiling 'Compiler-RT' modules. I am not sure for which purpose Compiler-RT module is required but it seems LLVM and CLANG has compiled well.
Is it possible that I can exclude Compiler-RT from download , build and installation:
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
Build LLVM and Clang only
Is it right to set my shared library path to use libstdc++.so.6 of GCC 4.5.0 and is Compiler-RT is a madatory step to download and build it with CLANG / LLVM
I found this sample code here - do I require Compiler-RT - I don't see reference to same but just wanted to confirm?

Resources