Bug 203223 - devel/llvm37: undefined references when compiling with -fopenmp=libomp
Summary: devel/llvm37: undefined references when compiling with -fopenmp=libomp
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Only Me
Assignee: Brooks Davis
Depends on:
Reported: 2015-09-20 18:06 UTC by stadtkind2
Modified: 2017-07-19 11:17 UTC (History)
1 user (show)

See Also:
bugzilla: maintainer-feedback? (brooks)


Note You need to log in before you can comment on or make changes to this bug.
Description stadtkind2 2015-09-20 18:06:40 UTC

I'm trying to compile a "hello world" OpenMP program, as per


"OpenMP 3.1 is fully supported, but disabled by default. To enable it, please use the -fopenmp=libomp command line option."

but all I get is (same with -fopenmp=libiomp5 and -fopenmp=libgomp):

$ clang37 -O -fopenmp=libomp omp.c  
/tmp/omp-ada729.o: In function `main':
omp.c:(.text+0xb): undefined reference to `omp_set_dynamic'
omp.c:(.text+0x10): undefined reference to `omp_get_max_threads'
omp.c:(.text+0x51): undefined reference to `__kmpc_fork_call'
/tmp/omp-ada729.o: In function `.omp_outlined.':
omp.c:(.text+0x81): undefined reference to `omp_get_thread_num'
omp.c:(.text+0xa6): undefined reference to `__kmpc_critical'
omp.c:(.text+0xbc): undefined reference to `__kmpc_end_critical'
omp.c:(.text+0xc6): undefined reference to `omp_get_num_threads'
omp.c:(.text+0xf4): undefined reference to `__kmpc_cancel_barrier'
clang-3.7: error: linker command failed with exit code 1 (use -v to see invocation)

$ pkg info llvm37
Name           : llvm37
Version        : 3.7.0_2
Installed on   : Sun Sep 13 16:00:11 CEST 2015
Origin         : devel/llvm37
Architecture   : freebsd:10:x86:64
Options        :
        OPENMP         : on

FreeBSD 10.2/amd64, llvm37 installed via pkg install.
Comment 1 Brooks Davis freebsd_committer 2015-09-21 18:55:35 UTC
Could you post the result of running:

clang37 -### -O -fopenmp=libomp omp.c
Comment 2 Shane 2015-09-22 02:17:20 UTC
Personally I have only had success by adding -L/usr/local/llvm37/lib -lomp - choosing either -liomp5 or -lgomp also works.

clang37 -fopenmp -L/usr/local/llvm37/lib -lomp omp.c

See http://blog.llvm.org/2015/05/openmp-support_22.html

Brooks - something for the todo list?? allow USE=compiler:openmp to recognize clang37 as valid if CC=clang37 CXX=clang++37 are set or pick clang37 over gcc?
Comment 3 stadtkind2 2015-09-22 11:40:30 UTC
(In reply to Brooks Davis from comment #1)

$ clang37 -### -O -fopenmp=libomp o>
clang version 3.7.0 (tags/RELEASE_370/final)
Target: x86_64-unknown-freebsd10.1
Thread model: posix
 "/usr/local/llvm37/bin/clang-3.7" "-cc1" "-triple" "x86_64-unknown-freebsd10.1" "-emit-obj" "-disable-free" "-main-file-name" "omp.c" "-mrelocation-model" "static" "-mthread-model" "posix" "-mdisable-fp-elim" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-target-cpu" "x86-64" "-dwarf-column-info" "-resource-dir" "/usr/local/llvm37/bin/../lib/clang/3.7.0" "-O2" "-fdebug-compilation-dir" "/home/space7/Personal/programming/omp" "-ferror-limit" "19" "-fmessage-length" "80" "-fopenmp" "-fnoopenmp-use-tls" "-mstackrealign" "-fobjc-runtime=gnustep" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-vectorize-loops" "-vectorize-slp" "-o" "/tmp/omp-35dde0.o" "-x" "c" "omp.c"
 "/usr/bin/ld" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld-elf.so.1" "--hash-style=both" "--enable-new-dtags" "-o" "a.out" "/usr/lib/crt1.o" "/usr/lib/crti.o" "/usr/lib/crtbegin.o" "-L/usr/lib" "/tmp/omp-35dde0.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "/usr/lib/crtend.o" "/usr/lib/crtn.o"
Comment 4 commit-hook freebsd_committer 2016-09-03 00:21:07 UTC
A commit references this bug:

Author: brooks
Date: Sat Sep  3 00:20:06 UTC 2016
New revision: 421280
URL: https://svnweb.freebsd.org/changeset/ports/421280

  Upgrade to 3.9.0 release.

  Improve support for -fopenmp with a hack inspired by a submission from
  Johannes Dieterich <dieterich@ogolem.org>.

  Implement a number of improvments submitted by lightside@gmx.com:
   - Add license information
   - Use VAR option helper for _USES_PYTHON variable
   - Add libxml2 to USE_GNOME for CLANG option
   - Sort variables for options (e.g. GOLD_*)

  Add USES=execinfo for LLDB.

  PR:		203223, 212334