简体   繁体   English

在OSX上使用clang ++进行编译,但不能包含/查找头文件

[英]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. 我正在尝试在Matlab上安装垃圾邮件工具箱,以优化稀疏表示问题。

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

At very first place, when I tried to compile it with compile.m script, it said that : 最初,当我尝试使用compile.m脚本进行编译时,它说:

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 . 然后,我找到了这篇文章,我按照下面的说明进行操作,似乎以前的错误已修复


在此处输入图片说明


But now, I am getting error says that: 但是现在,我收到错误提示:

...mexArchetypalAnalysis.cpp:32:
./linalg/mexutils.h:15:10:
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 : 当我转到源文件并注释此行时,它在包含iostream时给了我错误: 在此处输入图片说明

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. 因此,我可能认为这是有关库的问题,但是我对C ++或C语言并不熟悉,我需要一些帮助。

Finally, I fixed this by doing steps below: 最后,我通过执行以下步骤解决了这个问题:

Install gcc compiler and openmp support by homebrew : 通过homebrew 安装 gcc编译器和openmp支持:

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. 这样,您可以将cpp编译器与openmp支持一起使用。


Let run a test program to check if openmp works correctly: 让我们运行一个测试程序来检查openmp是否正常工作:

#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
    }

    printf("%d\t",i);
    return i;
}

int main(){

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

Compile: 编译:

gcc -fopenmp test.cpp -o run

or 要么

g++ -fopenmp test.cpp -o run

Output: 输出:

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. 如您所见,它们没有按顺序打印,这表明openmp可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM