title: Bad reloc address 0x0 in section.data C extensions for python
body: <p>I'm trying to write a script to automate a device in python. The device is programmed in C and I'm currently attempting to write a C wrapper in order for me to call those functions from Python later. I'm following <a href="http://csl.name/C-functions-from-Python/" rel="nofollow noreferrer">this</a> tutorial.</p>
  
  <p>The original C functions are hidden in a .lib file but the header file with all the functions initialization is provided. Here is a snippet of what it looks like</p>
  
  <pre><code>#ifdef VNX_ATTEN_EXPORTS
  #define VNX_ATTEN_API __declspec(dllexport)
  #else
  #define VNX_ATTEN_API __declspec(dllimport)
  #endif
  
  
  VNX_ATTEN_API void fnLDA_SetTestMode(bool testmode);
  VNX_ATTEN_API int fnLDA_GetNumDevices();
  VNX_ATTEN_API int fnLDA_GetDevInfo(DEVID *ActiveDevices);
  VNX_ATTEN_API int fnLDA_GetModelName(DEVID deviceID, char *ModelName);
  VNX_ATTEN_API int fnLDA_InitDevice(DEVID deviceID);
  VNX_ATTEN_API int fnLDA_CloseDevice(DEVID deviceID);
  VNX_ATTEN_API int fnLDA_GetSerialNumber(DEVID deviceID);
  VNX_ATTEN_API int fnLDA_GetDeviceStatus(DEVID deviceID);
  </code></pre>
  
  <p>Here is the C wrapper that I'm attempting to create</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;Python.h&gt;
  extern "C" {
  #include "VNX_atten.h"
  }
  //#include &lt;stdafx.h&gt;
  
  /*
   * Function to be called from Python
   */
  
  extern "C" { 
  static PyObject* py_fnLDA_SetTestMode(PyObject* self, PyObject* args)
  {
      double x;
      double y = 1;
      PyArg_ParseTuple(args, "d", &amp;x);
      if(x==1)
      fnLDA_SetTestMode(true);
      else
      fnLDA_SetTestMode(false);
  
      return Py_BuildValue("d", y);
  }
  
  /*
   * Another function to be called from Python
   */
  static PyObject* py_myOtherFunction(PyObject* self, PyObject* args)
  {
      double x, y;
      PyArg_ParseTuple(args, "dd", &amp;x, &amp;y);
      return Py_BuildValue("d", x*y);
  }
  
  /*
   * Bind Python function names to our C functions
   */
  static PyMethodDef myModule_methods[] = {
      {"fnLDA_SetTestMode", py_fnLDA_SetTestMode, METH_VARARGS},
      {"myOtherFunction", py_myOtherFunction, METH_VARARGS},
      {NULL, NULL}
  };
  
  /*
   * Python calls this to let us initialize our module
   */
  void initmyModule()
  {
      (void) Py_InitModule("myModule", myModule_methods);
  }
  
  }
  </code></pre>
  
  <p>The compilation call I'm trying is</p>
  
  <p>g++ -shared -IC:/Python27/include -LC:/Python27/libs myModule.cpp -lpython27 -o myModule.pyd</p>
  
  <p>Based on my searches I found <a href="https://stackoverflow.com/questions/17773269/bad-reloc-address-using-mingw">this</a> question on SO and tried this
  gcc -shared -IC:/Python27/include -LC:/Python27/libs myModule.c -DVNX_ATTEN_EXPORTS=1 -lpython27 -o myModule.pyd</p>
  
  <p>It hasn't helped.</p>
  
  <p>I'm getting the error "bad reloc address 0x0 in section .data" "collect2.exe: error: ld returned 1 exit status"</p>
  
  <p>Compilation is on a Windows XP (so 32 bit) platform using MinGW libraries and Python 2.7.</p>
  
  <p>Let me know if you need any further information and thanks in advance!!
  PS: Does this count as cross compiling?</p>
  
  <p>EDIT: ADDED THE ENTIRE ERROR MESSAGE</p>
  
  <pre><code>C:\cygwin\home\VRaghu\Attenuator\LDA SDK\ANSI C SDK\VNX_Atest&gt;g++ -shared -IC:/P
  ython27/include -LC:/Python27/libs myModule.cpp -DVNX_ATTEN_EXPORTS=1 -lpython27
   -o myModule.pyd
  
  C:\DOCUME~1\VRaghu\LOCALS~1\Temp\ccFkPRnf.o:myModule.cpp:(.text+0x40): undefined
   reference to `fnLDA_SetTestMode'
  
  C:\DOCUME~1\VRaghu\LOCALS~1\Temp\ccFkPRnf.o:myModule.cpp:(.text+0x50): undefined
   reference to `fnLDA_SetTestMode'
  
  c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\DOCUME~
  1\VRaghu\LOCALS~1\Temp\ccFkPRnf.o: bad reloc address 0x0 in section `.data'
  collect2.exe: error: ld returned 1 exit status
  </code></pre>