2016-06-25 134 views
1

我已經安裝了OpenMPxcode-select在我的macos中。MacOS上的OpenMP錯誤 - ld:找不到架構x86_64的符號

$ clang-omp --version 
clang version 3.5.0 
Target: x86_64-apple-darwin15.4.0 
Thread model: posix 

$ xcode-select --version 
xcode-select version 2343. 

在運行下面很簡單的代碼

1 #include <omp.h>                                        
    2 #include <stdio.h>                     
    3                          
    4 #define n 20                       
    5                          
    6 int main(){                       
    7                          
    8 int i;                        
    9 int tid;                        
10                          
11 omp_set_num_threads(3);                    
12 #pragma omp parallel for private(tid) schedule(static,1)            
13                          
14 for (i=0; i<n; i++) {                    
15 tid = omp_get_thread_num();                   
16 printf("Thread %d executing iteration %d\n", tid, i);            
17 }                         
18 }  

我得到錯誤

$ clang-omp -openmp parallel.c -v 

clang version 3.5.0 
Target: x86_64-apple-darwin15.4.0 
Thread model: posix 
"/usr/local/Cellar/clang-omp/2015-04-01/libexec/bin/clang-3.5" -cc1 -triple x86_64-apple-macosx10.11.0 -emit-obj -mrelax-all -disable-free -main-file-name parallel.c -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -v -dwarf-column-info -resource-dir /usr/local/Cellar/clang-omp/2015-04-01/libexec/bin/../lib/clang/3.5.0 -fdebug-compilation-dir /Users/prayagupd/prayag.data/workspace.programming/parallel-programming/openMP -ferror-limit 19 -fmessage-length 178 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.11.0 -fencode-extended-block-signature -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/63/jvvb4wy16gx6w76mkgsvn52m0000gn/T/parallel-32b98e.o -x c parallel.c 
clang -cc1 version 3.5.0 based upon LLVM 3.5.0svn default target x86_64-apple-darwin15.4.0 
ignoring nonexistent directory "/usr/local/Cellar/clang-omp/2015-04-01/libexec/usr/include" 
#include "..." search starts here: 
#include <...> search starts here: 
/usr/local/include 
/usr/local/Cellar/clang-omp/2015-04-01/libexec/bin/../lib/clang/3.5.0/include 
/usr/local/opt/libiomp/include/libiomp 
/usr/local/Cellar/clang-omp/2015-04-01/libexec/include/c++/v1 
/usr/include 
/System/Library/Frameworks (framework directory) 
/Library/Frameworks (framework directory) 
End of search list. 
"/usr/bin/ld" -dynamic -arch x86_64 -macosx_version_min 10.11.0 -o penmp /var/folders/63/jvvb4wy16gx6w76mkgsvn52m0000gn/T/parallel-32b98e.o -lSystem 
Undefined symbols for architecture x86_64: 
    "_omp_get_thread_num", referenced from: 
     _main in parallel-32b98e.o 
    "_omp_set_num_threads", referenced from: 
     _main in parallel-32b98e.o 
ld: symbol(s) not found for architecture x86_64 
clang-3.5: error: linker command failed with exit code 1 (use -v to see invocation) 

gcc甚至沒有找到omp.h

$ gcc parallel.c -fopenmp -o parallel 
parallel.c:1:10: fatal error: 'omp.h' file not found 
#include <omp.h> 
     ^
1 error generated. 

gcc版本是

$ gcc --version 
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn) 
Target: x86_64-apple-darwin15.4.0 
Thread model: posix 

回答

0

爲了您clang-omp的問題,你有沒有導出庫路徑? ala

export DYLD_LIBRARY_PATH=(OMPLIB PATH):$DYLD_LIBRARY_PATH 

也許您沒有從英特爾安裝OpenMP庫?現代鏗鏘聲(> 3.7)不包含在OS X中,現在支持OpenMP。

對於你的gcc問題,OS X實際上並不提供gcc,它只是將它鏈接到vanilla clang。所以你試圖用一個不支持OpenMP的編譯器來編譯它。如果你想要gcc,那麼通過ports或homebrew安裝它。

相關問題