title: Cython Interfacing with C
body: <p>Hi I am new to Cython and I would like to interface with my existing C code and I am having trouble linking my program.</p>
  <p>I have had a regular cython module working plenty of times before now I would like to interface with my C code just to be clear.</p>
  <p>Here is what my directory structure look like:</p>
  <pre><code>Example &lt;-- Master directory opened from here
    CSourceCode
      source.c
      source.h
    cprogram.pxd
    program.c
    program.pyx
    setup.py
    testing_interface.py
  </code></pre>
  <p><strong>Setup.py</strong></p>
  <pre><code>from setuptools import setup, Extension
  from Cython.Build import cythonize
  
  setup (
      ext_modules=cythonize([Extension(&quot;program&quot;, [&quot;program.pyx&quot;])])
  )
  </code></pre>
  <p><strong>cprogram.pxd</strong></p>
  <pre><code>cdef extern from &quot;CSourceCode/source.h&quot;:
      void hello()
  </code></pre>
  <p><strong>source.c</strong></p>
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void)
  {
  
      return 0;
  }
  
  void hello()
  {
      printf(&quot;HELLO FROM C&quot;);
  }
  </code></pre>
  <p><strong>source.h</strong></p>
  <pre><code>#ifndef _SOURCE
  #define _SOURCE &quot;source.h&quot;
  
  void hello();
  #endif
  </code></pre>
  <p><strong>program.pyx</strong></p>
  <pre><code>cimport cprogram
  
  def hello():
      cprogram.hello()
  </code></pre>
  <p><strong>testing_interface.py</strong></p>
  <pre><code>import program
  
  program.hello()
  </code></pre>
  <p><strong>trace</strong></p>
  <pre><code>python setup.py build_ext -i
  Compiling program.pyx because it changed.
  [1/1] Cythonizing program.pyx
  C:\Users\bmxfi\AppData\Local\Programs\Python\Python39\lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\bmxfi\Desktop\code\CPython\CInterfacing\Example\program.pyx
    tree = Parsing.p_module(s, pxd, full_module_name)
  running build_ext
  building 'program' extension
  C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I. -IC:\Users\bmxfi\AppData\Local\Programs\Python\Python39\include -IC:\Users\bmxfi\AppData\Local\Programs\Python\Python39\include -IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt /Tcprogram.c /Fobuild\temp.win-amd64-3.9\Release\program.obj
  program.c
  C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Users\bmxfi\AppData\Local\Programs\Python\Python39\libs /LIBPATH:C:\Users\bmxfi\AppData\Local\Programs\Python\Python39\PCbuild\amd64 /LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\lib\x64 /LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\ucrt\x64 /LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\um\x64 /EXPORT:PyInit_program build\temp.win-amd64-3.9\Release\program.obj /OUT:build\lib.win-amd64-3.9\program.cp39-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.9\Release\program.cp39-win_amd64.lib
     Creating library build\temp.win-amd64-3.9\Release\program.cp39-win_amd64.lib and object build\temp.win-amd64-3.9\Release\program.cp39-win_amd64.exp
  program.obj : error LNK2001: unresolved external symbol hello
  build\lib.win-amd64-3.9\program.cp39-win_amd64.pyd : fatal error LNK1120: 1 unresolved externals
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x64\\link.exe' failed with exit code 1120
  </code></pre>