title: Hello World program in Cython fails with gcc after installation of python-dev and linking libraries
body: <p>I created a simple hello world program and tried to execute the generated C program using gcc but no matter what I do I get a massive list of undefined references. </p>
  
  <p>There are many similar questions on SO but they all say to install python-dev (or some variation of it) or adding flags for linking and loading the libraries but I already tried both those options. </p>
  
  <p>hello.py</p>
  
  <pre><code>def main():
      print "Hello, World!"
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>I run:</p>
  
  <pre><code>cython --embed hello.py
  </code></pre>
  
  <p>Then I try to run some variation of gcc in the form:</p>
  
  <pre><code>gcc -I /usr/include/python2.7/ -L /usr/lib/python2.7 -lpython2.7 hello.c -o hello
  </code></pre>
  
  <p>I either get "Python.h" file not found or the following error message:</p>
  
  <pre><code>/tmp/ccxOQlAW.o: In function `__Pyx_PyObject_GetAttrStr':
  hello.c:(.text+0x95): undefined reference to `PyObject_GetAttr'
  /tmp/ccxOQlAW.o: In function `__pyx_pf_5hello_main':
  hello.c:(.text+0x149): undefined reference to `_Py_NoneStruct'
  hello.c:(.text+0x150): undefined reference to `_Py_NoneStruct'
  hello.c:(.text+0x15b): undefined reference to `_Py_NoneStruct'
  /tmp/ccxOQlAW.o: In function `__Pyx_InitCachedConstants':
  hello.c:(.text+0x1fd): undefined reference to `PyCode_New'
  /tmp/ccxOQlAW.o: In function `inithello':
  hello.c:(.text+0x2f4): undefined reference to `PyTuple_New'
  hello.c:(.text+0x33d): undefined reference to `PyString_FromStringAndSize'
  hello.c:(.text+0x3bd): undefined reference to `Py_InitModule4_64'
  hello.c:(.text+0x423): undefined reference to `PyModule_GetDict'
  hello.c:(.text+0x478): undefined reference to `PyImport_AddModule'
  hello.c:(.text+0x4cd): undefined reference to `PyObject_SetAttrString'
  hello.c:(.text+0x53b): undefined reference to `PyObject_SetAttrString'
  hello.c:(.text+0x644): undefined reference to `PyDict_SetItem'
  hello.c:(.text+0x7c8): undefined reference to `PyMethod_Type'
  hello.c:(.text+0x9ac): undefined reference to `PyDict_New'
  hello.c:(.text+0x9f8): undefined reference to `PyDict_SetItem'
  hello.c:(.text+0xb79): undefined reference to `PyErr_Occurred'
  hello.c:(.text+0xb85): undefined reference to `PyExc_ImportError'
  hello.c:(.text+0xb92): undefined reference to `PyErr_SetString'
  /tmp/ccxOQlAW.o: In function `__Pyx_FetchCommonType':
  hello.c:(.text+0xbb3): undefined reference to `PyImport_AddModule'
  hello.c:(.text+0xbf1): undefined reference to `PyObject_GetAttrString'
  hello.c:(.text+0xc24): undefined reference to `PyExc_TypeError'
  hello.c:(.text+0xc36): undefined reference to `PyErr_Format'
  hello.c:(.text+0xc63): undefined reference to `PyExc_TypeError'
  hello.c:(.text+0xc75): undefined reference to `PyErr_Format'
  hello.c:(.text+0xc81): undefined reference to `PyExc_AttributeError'
  hello.c:(.text+0xc89): undefined reference to `PyErr_ExceptionMatches'
  hello.c:(.text+0xc97): undefined reference to `PyErr_Clear'
  hello.c:(.text+0xca3): undefined reference to `PyType_Ready'
  hello.c:(.text+0xcc4): undefined reference to `PyObject_SetAttrString'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_get_doc':
  hello.c:(.text+0xdae): undefined reference to `PyString_FromString'
  hello.c:(.text+0xdda): undefined reference to `_Py_NoneStruct'
  hello.c:(.text+0xde5): undefined reference to `_Py_NoneStruct'
  hello.c:(.text+0xdea): undefined reference to `_Py_NoneStruct'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_set_doc':
  hello.c:(.text+0xe33): undefined reference to `_Py_NoneStruct'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_get_name':
  hello.c:(.text+0xec7): undefined reference to `PyString_InternFromString'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_set_name':
  hello.c:(.text+0xf51): undefined reference to `PyExc_TypeError'
  hello.c:(.text+0xf5e): undefined reference to `PyErr_SetString'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_set_qualname':
  hello.c:(.text+0x103d): undefined reference to `PyExc_TypeError'
  hello.c:(.text+0x104a): undefined reference to `PyErr_SetString'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_get_self':
  hello.c:(.text+0x10e3): undefined reference to `_Py_NoneStruct'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_get_dict':
  hello.c:(.text+0x1122): undefined reference to `PyDict_New'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_set_dict':
  hello.c:(.text+0x118a): undefined reference to `PyExc_TypeError'
  hello.c:(.text+0x1197): undefined reference to `PyErr_SetString'
  hello.c:(.text+0x11ca): undefined reference to `PyExc_TypeError'
  hello.c:(.text+0x11d7): undefined reference to `PyErr_SetString'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_get_closure':
  hello.c:(.text+0x127c): undefined reference to `_Py_NoneStruct'
  hello.c:(.text+0x1287): undefined reference to `_Py_NoneStruct'
  hello.c:(.text+0x128c): undefined reference to `_Py_NoneStruct'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_get_code':
  hello.c:(.text+0x12b2): undefined reference to `_Py_NoneStruct'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_set_defaults':
  hello.c:(.text+0x13ba): undefined reference to `_Py_NoneStruct'
  /tmp/ccxOQlAW.o:hello.c:(.text+0x13c4): more undefined references to `_Py_NoneStruct' follow
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_set_defaults':
  hello.c:(.text+0x13e6): undefined reference to `PyExc_TypeError'
  hello.c:(.text+0x13f3): undefined reference to `PyErr_SetString'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_get_defaults':
  hello.c:(.text+0x14d6): undefined reference to `_Py_NoneStruct'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_set_kwdefaults':
  hello.c:(.text+0x150d): undefined reference to `_Py_NoneStruct'
  hello.c:(.text+0x1517): undefined reference to `_Py_NoneStruct'
  hello.c:(.text+0x1539): undefined reference to `PyExc_TypeError'
  hello.c:(.text+0x1546): undefined reference to `PyErr_SetString'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_get_kwdefaults':
  hello.c:(.text+0x1629): undefined reference to `_Py_NoneStruct'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_set_annotations':
  hello.c:(.text+0x1660): undefined reference to `_Py_NoneStruct'
  hello.c:(.text+0x168c): undefined reference to `PyExc_TypeError'
  hello.c:(.text+0x1699): undefined reference to `PyErr_SetString'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_get_annotations':
  hello.c:(.text+0x1748): undefined reference to `PyDict_New'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_reduce':
  hello.c:(.text+0x17ad): undefined reference to `PyString_FromString'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_New':
  hello.c:(.text+0x17da): undefined reference to `_PyObject_GC_New'
  hello.c:(.text+0x1957): undefined reference to `PyObject_GC_Track'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_clear':
  hello.c:(.text+0x1e72): undefined reference to `PyMem_Free'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_dealloc':
  hello.c:(.text+0x1e9d): undefined reference to `PyObject_GC_UnTrack'
  hello.c:(.text+0x1eb6): undefined reference to `PyObject_ClearWeakRefs'
  hello.c:(.text+0x1ece): undefined reference to `PyObject_GC_Del'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_descr_get':
  hello.c:(.text+0x224a): undefined reference to `PyMethod_New'
  hello.c:(.text+0x2254): undefined reference to `_Py_NoneStruct'
  hello.c:(.text+0x2275): undefined reference to `PyMethod_New'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_repr':
  hello.c:(.text+0x2293): undefined reference to `PyString_AsString'
  hello.c:(.text+0x22a9): undefined reference to `PyString_FromFormat'
  /tmp/ccxOQlAW.o: In function `__Pyx_CyFunction_Call':
  hello.c:(.text+0x22d6): undefined reference to `PyCFunction_Call'
  /tmp/ccxOQlAW.o: In function `__pyx_CyFunction_init':
  hello.c:(.text+0x22e7): undefined reference to `PyCFunction_Call'
  /tmp/ccxOQlAW.o: In function `__Pyx_GetBuiltinName':
  hello.c:(.text+0x2357): undefined reference to `PyExc_NameError'
  hello.c:(.text+0x2369): undefined reference to `PyErr_Format'
  /tmp/ccxOQlAW.o: In function `__Pyx_GetModuleGlobalName':
  hello.c:(.text+0x2391): undefined reference to `PyDict_GetItem'
  /tmp/ccxOQlAW.o: In function `__Pyx_PyBytes_Equals':
  hello.c:(.text+0x2409): undefined reference to `PyString_Type'
  hello.c:(.text+0x241a): undefined reference to `PyString_Type'
  hello.c:(.text+0x24e2): undefined reference to `_Py_NoneStruct'
  hello.c:(.text+0x24f3): undefined reference to `PyString_Type'
  hello.c:(.text+0x2513): undefined reference to `_Py_NoneStruct'
  hello.c:(.text+0x2524): undefined reference to `PyString_Type'
  hello.c:(.text+0x254f): undefined reference to `PyObject_RichCompare'
  /tmp/ccxOQlAW.o: In function `__Pyx_PyObject_Call':
  hello.c:(.text+0x25f6): undefined reference to `PyObject_Call'
  hello.c:(.text+0x2602): undefined reference to `_PyThreadState_Current'
  hello.c:(.text+0x2614): undefined reference to `_Py_CheckRecursionLimit'
  hello.c:(.text+0x262b): undefined reference to `_Py_CheckRecursiveCall'
  hello.c:(.text+0x265f): undefined reference to `_PyThreadState_Current'
  hello.c:(.text+0x267d): undefined reference to `PyErr_Occurred'
  hello.c:(.text+0x2692): undefined reference to `PyExc_SystemError'
  hello.c:(.text+0x269f): undefined reference to `PyErr_SetString'
  /tmp/ccxOQlAW.o: In function `__Pyx_PyObject_CallMethO':
  hello.c:(.text+0x26d8): undefined reference to `_PyThreadState_Current'
  hello.c:(.text+0x26ea): undefined reference to `_Py_CheckRecursionLimit'
  hello.c:(.text+0x2701): undefined reference to `_Py_CheckRecursiveCall'
  hello.c:(.text+0x2734): undefined reference to `_PyThreadState_Current'
  hello.c:(.text+0x2752): undefined reference to `PyErr_Occurred'
  hello.c:(.text+0x2767): undefined reference to `PyExc_SystemError'
  hello.c:(.text+0x2774): undefined reference to `PyErr_SetString'
  /tmp/ccxOQlAW.o: In function `__Pyx__PyObject_CallOneArg':
  hello.c:(.text+0x2794): undefined reference to `PyTuple_New'
  /tmp/ccxOQlAW.o: In function `__Pyx_PyObject_CallOneArg':
  hello.c:(.text+0x2840): undefined reference to `PyCFunction_Type'
  hello.c:(.text+0x2882): undefined reference to `PyType_IsSubtype'
  /tmp/ccxOQlAW.o: In function `__Pyx_PyObject_CallNoArg':
  hello.c:(.text+0x28fe): undefined reference to `PyCFunction_Type'
  hello.c:(.text+0x2940): undefined reference to `PyType_IsSubtype'
  /tmp/ccxOQlAW.o: In function `__pyx_insert_code_object':
  hello.c:(.text+0x2ba0): undefined reference to `PyMem_Malloc'
  hello.c:(.text+0x2d01): undefined reference to `PyMem_Realloc'
  /tmp/ccxOQlAW.o: In function `__Pyx_CreateCodeObjectForTraceback':
  hello.c:(.text+0x2e0b): undefined reference to `PyString_FromString'
  hello.c:(.text+0x2e41): undefined reference to `PyString_FromFormat'
  hello.c:(.text+0x2e53): undefined reference to `PyString_FromString'
  hello.c:(.text+0x2ede): undefined reference to `PyCode_New'
  /tmp/ccxOQlAW.o: In function `__Pyx_AddTraceback':
  hello.c:(.text+0x305c): undefined reference to `_PyThreadState_Current'
  hello.c:(.text+0x306d): undefined reference to `PyFrame_New'
  hello.c:(.text+0x3090): undefined reference to `PyTraceBack_Here'
  /tmp/ccxOQlAW.o: In function `main':
  hello.c:(.text+0x3131): undefined reference to `Py_SetProgramName'
  hello.c:(.text+0x3136): undefined reference to `Py_Initialize'
  hello.c:(.text+0x3154): undefined reference to `PySys_SetArgv'
  hello.c:(.text+0x3170): undefined reference to `PyErr_Occurred'
  hello.c:(.text+0x317a): undefined reference to `PyErr_Print'
  hello.c:(.text+0x317f): undefined reference to `Py_FlushLine'
  hello.c:(.text+0x3188): undefined reference to `PyErr_Clear'
  hello.c:(.text+0x31ce): undefined reference to `Py_Finalize'
  /tmp/ccxOQlAW.o: In function `__Pyx_GetStdout':
  hello.c:(.text+0x31e7): undefined reference to `PySys_GetObject'
  hello.c:(.text+0x31f9): undefined reference to `PyExc_RuntimeError'
  hello.c:(.text+0x3206): undefined reference to `PyErr_SetString'
  /tmp/ccxOQlAW.o: In function `__Pyx_Print':
  hello.c:(.text+0x326f): undefined reference to `PyFile_SoftSpace'
  hello.c:(.text+0x3284): undefined reference to `PyFile_WriteString'
  hello.c:(.text+0x32bc): undefined reference to `PyFile_WriteObject'
  hello.c:(.text+0x32ea): undefined reference to `PyString_AsString'
  hello.c:(.text+0x32fa): undefined reference to `PyString_Size'
  hello.c:(.text+0x333c): undefined reference to `PyFile_SoftSpace'
  hello.c:(.text+0x3374): undefined reference to `PyFile_WriteString'
  hello.c:(.text+0x338b): undefined reference to `PyFile_SoftSpace'
  /tmp/ccxOQlAW.o: In function `__Pyx_PrintOne':
  hello.c:(.text+0x3453): undefined reference to `PyFile_SoftSpace'
  hello.c:(.text+0x3468): undefined reference to `PyFile_WriteString'
  hello.c:(.text+0x3486): undefined reference to `PyFile_WriteObject'
  hello.c:(.text+0x349d): undefined reference to `PyFile_WriteString'
  /tmp/ccxOQlAW.o: In function `__Pyx_check_binary_version':
  hello.c:(.text+0x355b): undefined reference to `PyOS_snprintf'
  hello.c:(.text+0x3560): undefined reference to `Py_GetVersion'
  hello.c:(.text+0x3584): undefined reference to `PyOS_snprintf'
  hello.c:(.text+0x35e0): undefined reference to `PyOS_snprintf'
  hello.c:(.text+0x35f9): undefined reference to `PyErr_WarnEx'
  /tmp/ccxOQlAW.o: In function `__Pyx_InitStrings':
  hello.c:(.text+0x3667): undefined reference to `PyUnicodeUCS4_DecodeUTF8'
  hello.c:(.text+0x368f): undefined reference to `PyString_InternFromString'
  hello.c:(.text+0x36ba): undefined reference to `PyString_FromStringAndSize'
  /tmp/ccxOQlAW.o: In function `__Pyx_PyObject_IsTrue':
  hello.c:(.text+0x3708): undefined reference to `_Py_TrueStruct'
  hello.c:(.text+0x3719): undefined reference to `_Py_ZeroStruct'
  hello.c:(.text+0x372c): undefined reference to `_Py_NoneStruct'
  hello.c:(.text+0x3749): undefined reference to `PyObject_IsTrue'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>I already installed python-dev (and its variations). Replacing header files with "python2.7/header_file" still results in undefined references. I'm running Ubuntu Linux 3.13.0-73-generic. </p>
  
  <p><strong>How can I get my cython code to compile using gcc?</strong></p>
  
  <p>Thank you.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>find /usr/include/ -name Python.h output:</p>
  
  <pre><code>/usr/include/python2.7/Python.h
  /usr/include/python3.4m/Python.h
  </code></pre>
  
  <p>find /usr/lib* -name libpython2.7.so output:</p>
  
  <pre><code>/usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so
  </code></pre>
  
  <p>I'm building on a 64 bit system and the gcc target is 64 bit (--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu)</p>