Search code examples
gccprogram-entry-pointelfmicrochipxc32

In function `_main_entry' undefined reference to `main'


Here is my problem, I build an archive with "xc32-ar.exe" with this command line.

"C:\Program Files (x86)\Microchip\xc32\v2.30\bin\xc32-ar.exe"   r dist/default/production/MyApp.X.a build/default/production/source/Main.o

With this lib and an other I try to build a .elf.

"C:\Program Files (x86)\Microchip\xc32\v2.30\bin\xc32-gcc.exe"   -mprocessor=PIC32MX340F512H  -o dist/default/production/MyApp.X.production.elf dist/default/production/MyApp.X.a ..\..\MyLib\MyLib.X\dist\default\production\MyLib.X.a      -DXPRJ_default=default  -legacy-libc    -Wl,--defsym=__MPLAB_BUILD=1,--defsym=_min_heap_size=2576,--no-code-in-dinit,--no-dinit-in-serial-mem,-L"include/BM",-Map="dist/default/production/MyApp.X.production.map",--report-mem,--memorysummary,dist/default/production/memoryfile.xml -mdfp="C:/Users/Public/.mchp_packs/Microchip/PIC32MX_DFP/1.5.259"

And I have this error

C:\Users\PUBLIC~1\AppData\Local\Temp\cc0YJyY1.o: In function `_main_entry':
(.text.main_entry+0x24): undefined reference to `main'
C:\Users\PUBLIC~1\AppData\Local\Temp\cc0YJyY1.o: In function `_main_entry':
(.text.main_entry+0x28): undefined reference to `main'
collect2.exe: error: ld returned 255 exit status

I use xc32-nm to list the index table.

Main.o:
bfc02ff0 t __config_BFC02FF0
bfc02ff4 t __config_BFC02FF4
bfc02ff8 t __config_BFC02FF8
bfc02ffc t __config_BFC02FFC
00000070 T main

Is it possible to do this?


Solution

  • Is it possible to do this?

    Yes: add -u main to your link line.

    To understand what's wrong with your command line, read this or this.