title: Using Openmp 4/5 in Visual Studio 2019 using clang-cl
body: <p>I am trying to run a simple project with OpenMP. Since Visual Studio only supports OpenMP 2 so I try to compile and run the project using LLVM clang-cl that comes with Visual Studio 2019. The compilation part seems to be ok, but in the link phase, the linker cannot resolve the OMP functions.</p>
  
  <p>This is my code, there is only 1 file:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void fn() {
      #pragma omp parallel num_threads(5)
      {
          int i;
          #pragma omp task depend(in : i)
          for (i = 0; i &lt; 1; i++) {
              printf("task\n");
          }
      }
  }
  
  int main() {
      printf("hello\n");
      fn();
  }
  </code></pre>
  
  <p>My Visual Studio project properties:</p>
  
  <ul>
  <li><code>Windows SDK version</code>: 10.0(latest installed version) (10.0.18362.0)</li>
  <li><code>Platform toolset</code>: LLVM (clang-cl)</li>
  <li><code>C/c++ - Command Line - Additional Options</code>: <code>/Zc:twoPhase- -Xclang -fopenmp -v</code></li>
  <li><code>Linker - Additional Dependencies</code>: <code>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\lib\libomp.lib</code> and <code>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\lib\libiomp5md.lib</code></li>
  <li><code>Linker - Additional Library Directories</code>: <code>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\lib</code></li>
  <li><code>Linker - Command Lines - Additional Options</code>: <code>-fopenmp -verbose</code></li>
  </ul>
  
  <p>Error log when running the project</p>
  
  <pre><code>1&gt;lld-link : error : undefined symbol: __kmpc_global_thread_num
  1&gt;&gt;&gt;&gt; referenced by D:\Repositories\Test-clang\Test-clang\Source.cpp:4
  1&gt;&gt;&gt;&gt;               x64\Debug\Source.obj:(void __cdecl fn(void))
  1&gt;
  1&gt;lld-link : error : undefined symbol: __kmpc_push_num_threads
  1&gt;&gt;&gt;&gt; referenced by D:\Repositories\Test-clang\Test-clang\Source.cpp:7
  1&gt;&gt;&gt;&gt;               x64\Debug\Source.obj:(void __cdecl fn(void))
  1&gt;
  1&gt;lld-link : error : undefined symbol: __kmpc_fork_call
  1&gt;&gt;&gt;&gt; referenced by D:\Repositories\Test-clang\Test-clang\Source.cpp:7
  1&gt;&gt;&gt;&gt;               x64\Debug\Source.obj:(void __cdecl fn(void))
  1&gt;
  1&gt;lld-link : error : undefined symbol: __kmpc_omp_task_alloc
  1&gt;&gt;&gt;&gt; referenced by D:\Repositories\Test-clang\Test-clang\Source.cpp:10
  1&gt;&gt;&gt;&gt;               x64\Debug\Source.obj:(.omp_outlined._debug__)
  1&gt;
  1&gt;lld-link : error : undefined symbol: __kmpc_omp_task_with_deps
  1&gt;&gt;&gt;&gt; referenced by D:\Repositories\Test-clang\Test-clang\Source.cpp:10
  1&gt;&gt;&gt;&gt;               x64\Debug\Source.obj:(.omp_outlined._debug__)
  1&gt;Done building project "Test-clang.vcxproj" -- FAILED.
  </code></pre>
  
  <p>I am using Visual Studio Community 2019. So how do I config the project in order to OpenMP work?</p>
  
  <hr>
  
  <p>I have also tried to compile like in this <a href="https://stackoverflow.com/questions/55976484/llvm-clang-8-compilation-of-openmp-code-in-windows">answer</a> and it works. </p>
  
  <pre><code>clang -fopenmp -o Source.obj -c Source.cpp
  clang -fopenmp -o Source.exe Source.obj
  </code></pre>
  
  <p>It works for clang-cl too</p>
  
  <pre><code>clang-cl -Xclang -fopenmp -o Source.obj -c Source.cpp
  clang-cl /clang:-fopenmp -o Source.exe Source.obj -v
  </code></pre>
  
  <p>But I don't know how to make Visual Studio build the project using the above way.</p>