Bug 222858

Summary: Clang doesn't find <omp.h> and libomp.so when compiling with -fopenmp
Product: Base System Reporter: DarenK <equilibrium556>
Component: miscAssignee: freebsd-toolchain (Nobody) <toolchain>
Status: Closed DUPLICATE    
Severity: Affects Some People CC: dim, emaste, jbeich, mi, portmgr
Priority: ---    
Version: 11.1-STABLE   
Hardware: Any   
OS: Any   
See Also: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=210337
Description Flags
OpenMP C test file none

Description DarenK 2017-10-08 11:25:39 UTC
Created attachment 186994 [details]
OpenMP C test file

Trying to compile C code that utilizes OpenMP with Clang on FreeBSD 11.1 results in some compiler/linker errors:

Trying to compile with:
clang -o openmp_test openmp_test.c -fopenmp

openmp_test.c:1:10: fatal error: 'omp.h' file not found
It is located in /usr/local/include (openmp package) though

Trying again to compile with:
clang -o openmp_test openmp_test.c -fopenmp -I/usr/local/include

/usr/bin/ld: cannot find -lomp

It is located in /usr/local/lib (openmp package)

Finally, it compiles with:
clang -o openmp_test openmp_test.c -fopenmp -I/usr/local/include -L/usr/local/lib

Shouldn't it add the right search paths for OpenMP from the get-go when issuing -fopenmp?
Comment 1 Dimitry Andric freebsd_committer 2017-10-09 15:54:13 UTC
As long as libomp is in ports, you will have to manually add -I${LOCALBASE}/include to CFLAGS, and -L${LOCALBASE}/lib to LDFLAGS.  This is how it has always been with ports.

There are some preliminary plans for adding openmp to the base system, but this has the disadvantage that it can't be updated that easily anymore.
Comment 2 Mikhail Teterin freebsd_committer 2018-07-10 17:40:17 UTC
Meanwhile, perhaps, Uses/compiler.mk can be taught to use the base clang with the right options, when compiler:openmp is among ${USES} -- instead of insisting on gcc?
Comment 3 Jan Beich freebsd_committer 2018-07-10 18:37:02 UTC
(In reply to Mikhail Teterin from comment #2)
That would be bug 210337. USES=compiler:openmp cannot use Clang in base on FreeBSD 10.* because -fopenmp is ignored there, cannot use Clang from devel/llvm60 on FreeBSD 10.* because OPENMP is unconditionally disabled in the port, cannot use Clang on non-x86 where LLVM openmp isn't supported (on FreeBSD) and Clang cannot use libgomp (from lang/gcc*). And lang/gcc* is often required by USES=fortran consumers directly or via libgcc_s pollution.
Comment 4 Jan Beich freebsd_committer 2019-05-19 03:32:20 UTC
libomp.so is part of base since 11.3/12.1, so -fopenmp should work without having to specify -I/-L flags.

*** This bug has been marked as a duplicate of bug 236062 ***