title: Error when linking .o files using ld on WIndows
body: <p>Two C files are compiled as shown:</p>
  <p><code>gcc -g -c -Wall -I../include blink.c -o blink.o</code></p>
  <p><code>gcc -g -c -Wall -I../include led/led.c -o led/led.o</code></p>
  <p>These operations appear to be successful (the correct files are produced).</p>
  <p>When attempting to link the two .o files with the command:</p>
  <p><code>ld -Map blink.map -T make.ld -N -o blink.exe blink.o led/led.o</code></p>
  <p>This error is returned:</p>
  <p><code>undefined reference to `__main'</code></p>
  <p>As suggested on another post, I tried adding <code>-r</code>, but that instead results in this error shown below:</p>
  <pre><code>C:\mingw\bin\ld.exe: address 0x0 of blink.exe section `data' is not within region `ram'
  C:\mingw\bin\ld.exe: address 0x0 of blink.exe section `bss' is not within region `ram'
  C:\mingw\bin\ld.exe: address 0xd0 of blink.exe section `text' is not within region `ram'
  C:\mingw\bin\ld.exe: address 0x28 of blink.exe section `.xdata' is not within region `ram'
  C:\mingw\bin\ld.exe: address 0x30 of blink.exe section `.pdata' is not within region `ram'
  C:\mingw\bin\ld.exe: address 0x40 of blink.exe section `.rdata$zzz' is not within region `ram'
  </code></pre>
  <p>I am using Windows 10, and have tried this using both Cygwin64 Terminal and MinGW, but get the exact same result with both.</p>
  <p>I am fairly sure that it is not a RAM issue, as there is '320K' (which I believe should be more than enough for a simple program like this) assigned in the <code>make.ld</code> file, shown below:</p>
  <pre><code>ENTRY (main)
  
  MEMORY
  {
      ram : ORIGIN = 0x20000000, LENGTH = 320K /* 0x2000 0000 - 0x2004 FFFF */
      rom : ORIGIN = 0x08000000, LENGTH = 1024K /* 0x0800 0000 - 0x080F FFFF */
  }
  
  SECTIONS
  {
      data :
      {
          _DataStart = . ;
          *(.data)
          _DataEnd   = . ;
      } &gt;ram 
  
      bss :
      {
          _BssStart = . ;
          *(.bss)
          _BssEnd   = . ;
      } &gt;ram 
  
      text :
      {
          *(.text)
      } &gt;ram 
  }
  </code></pre>
  <p>For reference here are the three other files:</p>
  <p>blink.c</p>
  <pre class="lang-c prettyprint-override"><code>int main(void)
  {
      ledInit();
      while (1)
      {
          ledToggle();
          delay_ms(500);
      }
      return 0;
  }
  </code></pre>
  <p>led/led.c</p>
  <pre class="lang-c prettyprint-override"><code>#include &quot;../stm32f7/onChipPeripherals.h&quot;            
  
  void ledInit(void)
  {
      (*((uint32_t volatile *)(GPIO_A + GPIO_BSRR_OFFSET))) = 0xFFFF0000;
      (*((uint32_t volatile *)(GPIO_A + GPIO_MODER_OFFSET))) = 0x00000010;
  }
  
  void ledToggle(void)
  {
      if ((*((uint32_t volatile *)(GPIO_A + GPIO_BSRR_OFFSET))) &amp; 0x0000FFFF)
          (*((uint32_t volatile *)(GPIO_A + GPIO_BSRR_OFFSET))) = 0xFFFF0000;
      else
          (*((uint32_t volatile *)(GPIO_A + GPIO_BSRR_OFFSET))) = 0x0000FFFF;
  }
  
  void delay_ms(int milliseconds)
  {
      long volatile cycles = (milliseconds * CYCLES_PER_MS);
      while (cycles != 0)
          cycles--;
  }
  </code></pre>
  <p>stm32f7/onChipPeripherals.h</p>
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdint.h&gt;
  
  /* GPIO Registers */
  #define GPIO_A                                     (*((uint32_t volatile *)0x40020000))
  
  #define GPIO_MODER_OFFSET                          (0x00) // GPIO port mode register
  #define GPIO_OTYPER_OFFSET                         (0x04) // GPIO port output type register
  #define GPIO_OSPEEDR_OFFSET                        (0x08) // GPIO port output speed register
  #define GPIO_PUPDR_OFFSET                          (0x0C) // GPIO port pull-up/pull-down register
  #define GPIO_IDR_OFFSET                            (0x10) // GPIO port input data register
  #define GPIO_ODR_OFFSET                            (0x14) // GPIO port output data register
  #define GPIO_BSRR_OFFSET                           (0x18) // GPIO port bit set/reset register
  #define GPIO_LCKR_OFFSET                           (0x1C) // GPIO port configuration lock register
  #define GPIO_AFRL_OFFSET                           (0x20) // GPIO alternate function low register
  #define GPIO_AFRH_OFFSET                           (0x24) // GPIO alternate function high register
  </code></pre>
  <p>I would hugely appreciate any suggestions or guidance on what to do or try next, as I am a little stuck and unsure from here.</p>