title: CMake, Clang and OpenMP on MacOS Big Sur
body: <p>I'm having trouble compiling a project requiring OpenMP using CMake and clang, I set my <code>CMakeLists.txt</code> like this</p>
  <pre><code>cmake_minimum_required(VERSION 3.20)
  project(cmat C)
  
  set(CMAKE_C_STANDARD 11)
  
  include_directories(&quot;/usr/local/include&quot; &quot;/usr/local/opt/llvm/include&quot;)
  link_directories(&quot;/usr/local/lib&quot; &quot;/usr/local/opt/llvm/lib&quot;)
  
  add_library(cmat SHARED cmat.c Calculation/_Basic_Calculate_.c Calculation/_Basic_Calculate_.h)
  </code></pre>
  <p>And when I started to build my project, it gave error</p>
  <pre><code>Undefined symbols for architecture x86_64:
    &quot;_omp_get_thread_num&quot;, referenced from:
        _NmMulMat in _Basic_Calculate_.c.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  make[3]: *** [libcmat.dylib] Error 1
  make[2]: *** [CMakeFiles/cmat.dir/all] Error 2
  make[1]: *** [CMakeFiles/cmat.dir/rule] Error 2
  make: *** [cmat] Error 2
  </code></pre>
  <p>I've tried some of the other answers like <a href="https://stackoverflow.com/questions/37969440/clang-openmp-and-cmake">this</a> and <a href="https://stackoverflow.com/questions/46414660/macos-cmake-and-openmp">this</a>, but they just don't work for me.</p>
  <p>The clang version for my Mac is 13.0.0 and CMake is of 3.21.3_1, I'm using Clion as IDE, and such command will work when compiling files by shell</p>
  <pre><code>clang -Xpreprocessor -fopenmp -I/usr/local/include -L/usr/local/lib -lomp filename.c -o output
  </code></pre>
  <p>Great appreciate for your help.</p>