Bug 222858 - Clang doesn't find <omp.h> and libomp.so when compiling with -fopenmp
Summary: Clang doesn't find <omp.h> and libomp.so when compiling with -fopenmp
Status: Closed DUPLICATE of bug 236062
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 11.1-STABLE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-toolchain (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-08 11:25 UTC by DarenK
Modified: 2019-05-19 03:32 UTC (History)
5 users (show)

See Also:


Attachments
OpenMP C test file (66 bytes, text/x-csrc)
2017-10-08 11:25 UTC, DarenK
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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 freebsd_triage 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 freebsd_triage 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 freebsd_triage 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 freebsd_triage 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 ***