Creating a static library with OpenMP offloading code

Dear all,

I have a question w.r.t. creating a *static* library containing OpenMP offloading code.

Using Clang/LLVM 9, I can successfully create an executable from source files with OpenMP target regions by creating a *shared* library and linking everything with clang++ in the style

clang++ -fpic -fopenmp -fopenmp-targets=... -c file_a.cpp
clang++ -fpic -fopenmp -fopenmp-targets=... -c file_b.cpp
clang++ -shared -fopenmp -fopenmp-targets=... -o liboffload.so file_a.o file_b.o
clang++ -fopenmp -fopenmp-targets=... -loffload -o main main.o

However, I did not succeed in doing this with a *static* library. Since I do not know of any argument I can give to clang++ to create a static instead of shared library, I tried with llvm-ar, since I assume it is OpenMP-offloading-aware.

So I did

llvm-ar r liboffload.a file_a.o file_b.o

and when I objdump liboffload.a, it contains offloading-related symbols such as .omp_offloading.entries and __CLANG_OFFLOAD_BUNDLE__..., so everything seems OK.

But when I try something like

clang++ -fopenmp -fopenmp-targets=... -loffload -o main main.o

I get undefined references for functions in liboffload.a, and when I add liboffload.a to the arguments, I get an executable, but at runtime the offload entries for the target regions are missing.

So my question is: Is there a way of getting this to work with a static instead of shared library? I would appreciate an answer a lot.

Thanks in advance for any help,

Kai