2017-08-31 5 views
3

J'ai construit clang 4.0 à partir de la source sur Ubuntu 16.04 et j'essaie de compiler un simple programme OpenMP, mais recevez les erreurs suivantes.OpenMP ne pas lier correctement lors de la compilation avec clang

/tmp/test-7f2c7c.o: In function `main': 
/home/me/sf_shared/test.c:(.text+0x52): undefined reference to `__kmpc_fork_call' 
/tmp/test-7f2c7c.o: In function `.omp_outlined.': 
/home/me/sf_shared/test.c:(.text+0xd9): undefined reference to `__kmpc_for_static_init_4' 
/home/me/sf_shared/test.c:(.text+0x16d): undefined reference to `__kmpc_for_static_fini' 
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation) 

Pour compiler J'utilise ./bin/clang ~/sf_shared/tset.c -fopenmp où bin est le dossier bin où j'ai construire tintement de la source et test.c est un programme simple OpenMP.

Ajout -v résultats dans les domaines suivants

clang version 4.0.1 
Target: x86_64-unknown-linux-gnu 
Thread model: posix 
InstalledDir: /home/me/release_build/./bin 
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5 
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0 
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6 
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.0.0 
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0 
Candidate multilib: .;@m64 
Selected multilib: .;@m64 
"/home/me/release_build/bin/clang-4.0" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all 
-disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.c -mrelocation-model static 
-mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables 
-fuse-init-array -target-cpu x86-64 -v -dwarf-column-info -debugger-tuning=gdb -resource-dir /home/me 
/release_build/bin/../lib/clang/4.0.1 -internal-isystem /usr/local/include -internal-isystem /home/me 
/release_build/bin/../lib/clang/4.0.1/include -internal-externc-isystem /usr/include/x86_64-linux-gnu 
-internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/me 
/release_build -ferror-limit 19 -fmessage-length 117 -fopenmp -fobjc-runtime=gcc -fdiagnostics-show-option -o 
tmp/test-c9b0bd.o -x c /home/me/sf_shared/test.c 
clang -cc1 version 4.0.1 based upon LLVM 4.0.1 default target x86_64-unknown-linux-gnu 
ignoring nonexistent directory "/include" 
#include "..." search starts here: 
#include <...> search starts here: 
/usr/local/include 
/home/me/release_build/bin/../lib/clang/4.0.1/include 
/usr/include/x86_64-linux-gnu 
/usr/include 
End of search list. 
"/usr/bin/ld" -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ 
ld-linux-x86-64.so.2 -o a.out /usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc 
/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/5.4.0/crtbegin.o -L/usr/ 
lib/gcc/x86_64-linux-gnu/5.4.0 -L/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu -L/lib/ 
x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../.. -L/ 
home/me/release_build/bin/../lib -L/lib -L/usr/lib /tmp/test-c9b0bd.o -lomp -lgcc --as-needed -lgcc_s 
--no-as-needed -lpthread -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/5.4.0/ 
crtend.o /usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/crtn.o 
/tmp/test-c9b0bd.o: In function `main': 
/home/me/sf_shared/test.c:(.text+0x52): undefined reference to `__kmpc_fork_call' 
/tmp/test-c9b0bd.o: In function `.omp_outlined.': 
/home/me/sf_shared/test.c:(.text+0xd9): undefined reference to `__kmpc_for_static_init_4' 
/home/me/sf_shared/test.c:(.text+0x15f): undefined reference to `__kmpc_for_static_fini' 
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation) 

Toute idée pourquoi les sections OpenMP ne sont pas liés correctement?

J'ai inclure test.c ci-dessous si quelqu'un est curieux

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

int main() { 
    printf("Max threads: %d\n", omp_get_max_threads()); 
    omp_set_dynamic(0); 
    omp_set_num_threads(omp_get_max_threads()); 

    #pragma omp parallel for 
    for (int i = 0; i < 32; ++i) { 
     printf("I am thread %d\n", omp_get_thread_num()); 
    } 
} 
+0

https://stackoverflow.com/questions/33357029/using-openmp-with-clang? –

+0

en utilisant '-fopenmp = libiomp5' a résolu le problème, mais qu'est-ce que libiomp5 et pourquoi ne fonctionne-t-il pas correctement sans cela? La réponse d'Andrey Bokhanko à la question que vous avez partagée dit "_Vous devez utiliser -fopenmp = libomp pour activer OpenMP en clang. -fopenmp ne fait que lier libgomp mais ignore toutes les pragmas.Wird, je sais - et sera changé dans le tronc soon_ ", se référant à clang 3.7. Cela n'a-t-il toujours pas été traité dans le paragraphe 4.0.1? – klskjndf

Répondre

0

Installation du package libiomp5 et le changement -fopenmp à -fopenmp=libiomp5 lors de la compilation a résolu le problème.