Microos Microos - 1 month ago 29x
C++ Question

Compiling with clang++ on OSX but cannot include/find header files

I'm trying to install the spams toolbox on Matlab for optimizing sparse representation problems.

The download page-> http://spams-devel.gforge.inria.fr/downloads.html

At very first place, when I tried to compile it with
script, it said that :

clang: error: unsupported option '-fopenmp'
error: command 'clang' failed with exit status 1

And then, I found this post, I followed the instruction below, and it seems the previous error was fixed.

enter image description here

But now, I am getting error says that:

fatal error: 'typeinfo' file not found
#include <typeinfo>

When I went to the source file and comment this line, it gave me error on including iostream:
enter image description here

So I may think it is the problem about the libraries but I am not familiar with the C++ or C something, I need some helps.


Finally, I fixed this by doing steps below:

Install gcc compiler and openmp support by homebrew:

brew install gcc --without-multilib

After installation, In command line:

alias gcc=gcc-6
alias clang=gcc-6
alias g++=g++-6

by doing so, you can use the cpp compiler with openmp support.

Let run a test program to check if openmp works correctly:

#include <stdio.h>
#include <omp.h>

int  print(int i){
    int tmp = 0;
    for(int i=0;i<100000000;i++){
        tmp += 1; // time consuming loop

    return i;

int main(){

    #pragma omp parallel for
    for(int i=0; i<10;i++){
    return 0;


gcc -fopenmp test.cpp -o run


g++ -fopenmp test.cpp -o run


0   8   3   6   1   9   4   7   2   5

As you can see they are not printed in orders, this indicates openmp works correctly.