<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/152360>152360</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Compilation of a valid OpenMP program fails with linker error
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            openmp:libomp,
            openmp:libomptarget
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          jprotze
      </td>
    </tr>
</table>

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

int main(int argc, char **argv) {
 printf("omp_target_is_present(%p, %i): %i\n", argv, omp_get_initial_device(),
         omp_target_is_present(argv, omp_get_initial_device()));
  return 0;
}
```
Compiling the program results in a linker error:
```
$ clang -fopenmp omp_target_is_present.c
/usr/bin/ld: /tmp/omp_target_is_present-96f7d7.o: in function `main':
omp_target_is_present.c:(.text+0x3a): undefined reference to `omp_target_is_present'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

Expected behavior: Clang should compile and link all valid OpenMP programs with `-fopenmp` flag.

Solution: libomp should implement (weak) stub versions of all target-related functions. If we don't want to pay the cost of propagating the function calls from libomp to libomptarget (as for example currently done for `omp_get_initial_device()`), we could simply change the link ordering and link libomptarget before libomp.

@mjklemm @jhuber6 @Meinersbur what do you think?
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVN1u4ygUfhpyc5SI4J84F75w04m0F6NdaR-gwnBs02JAgNN2n34FjruzM600kZUQH_t8P-eHh6BGg9iS6oFUjzu-xMn69tl5G__BXW_le0tqer9oR1ihjNCLRCDFxc7uMJHi2y-BEKWyHyHaKRNh5soQ1qQj96Mg7AJi4h4I6wjruB9vhJ2BnB4I7cB5ZeJAWEMYs7N7ityPGJ9UeHIeA5qYQ5VLWQirFGFnUnTrsboYwliKrEkvkDLk142KiusniTclMKc4E3ZJgNvnK7DfS5WvIisAj3HxBuj6n5we0_cPVib3lFZm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