在函数“_main_entry”中未定义对“main”的引用

In function `_main_entry' undefined reference to `main'

这是我的问题,我用这个命令行用“xc32-ar.exe”构建了一个存档。

"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

使用这个库和另一个库,我尝试构建一个 .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"

我有这个错误

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

我使用 xc32-nm 列出索引 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?

是:将 -u main 添加到您的 link 行。

要了解您的命令行有什么问题,请阅读 this or this