• AVR Freaks

Helpful ReplyHot!PIC24FJ128GA006 : Undefined reference to main

Author
SNTT
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2009/10/14 03:42:46
  • Location: 0
  • Status: offline
2009/10/14 03:44:45 (permalink)
0

PIC24FJ128GA006 : Undefined reference to main

Urgent!!! Help!!! I am new to PIC24, using MPLAB8.10 with Microchip C30 Toolsuite Microchip ASM30 Assembler (pic30-as.exe) to build my assembly source code, but Build failed...
c:/program files/microchip/mplab c30/bin/bin/../../lib\libpic30-coff.a(crt0_standard.o)(.init+0x1c):fake: undefined reference to `main'
Link step failed.

I put only 3 line in my assembly source code:
MOV.B #0X1E, W1
MOV.B #0X84, W1
MOV.B #0X80, W1

I have no idea why I got this error.
Do I miss out any important setting?
Is it because of my MPLAB version or my language toolsuite do not match or support PIC24?
Or, because I didn't put any configuration in my assembly source code?

In the MPLAB project, I did select PIC24F128GA006 under configuration device and include the header file p24FJ128GA006.h and p24FJ128GA006.inc. The linker script p24FJ128GA006.gld also added.

Is there any ways to solve the 'undefined reference to 'main''???
Please help.....
#1
A.R.T
Super Member
  • Total Posts : 308
  • Reward points : 0
  • Joined: 2006/05/12 03:13:15
  • Location: Cambridge , UK
  • Status: offline
RE: PIC24FJ128GA006 : Undefined reference to main 2009/10/14 03:56:43 (permalink)
0
your program needs a 'main' in it as an entry point, unless you write your own reset stuff and remove the library from the linker file

#2
MBedder
Circuit breaker
  • Total Posts : 6749
  • Reward points : 0
  • Joined: 2008/05/30 11:24:01
  • Location: Zelenograd, Russia
  • Status: offline
RE: PIC24FJ128GA006 : Undefined reference to main 2009/10/14 03:57:26 (permalink) ☄ Helpfulby bmwman91 2018/11/25 19:48:06
+3 (3)
Add the following lines to your code:


.include        "p24xxxx.inc"   ; Include chip definitions

.global __reset ; Tell the linker where your code starts

.text           ; Start a code section

__reset:        ; A mandatory label. Note the double underscore
; Place your code here

.end            ; End of program. Place an empty string after this directive to avoid warning



#3
MBedder
Circuit breaker
  • Total Posts : 6749
  • Reward points : 0
  • Joined: 2008/05/30 11:24:01
  • Location: Zelenograd, Russia
  • Status: offline
RE: PIC24FJ128GA006 : Undefined reference to main 2009/10/14 03:59:49 (permalink)
+1 (1)
ORIGINAL: atsoft

your program needs a 'main' in it as an entry point, unless you write your own reset stuff and remove the library from the linker file
Declaring .global __reset makes this itself - no need to declare __main and remove anything.
#4
edgar.rene
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2009/10/19 19:20:20
  • Location: 0
  • Status: offline
RE: PIC24FJ128GA006 : Undefined reference to main 2009/10/20 08:17:54 (permalink)
0
YEs, you don't need __main, you have to place : __reset not __main, you just look at gld file, so, you can see all interrupts for declare!!
 
good luck!
#5
MBedder
Circuit breaker
  • Total Posts : 6749
  • Reward points : 0
  • Joined: 2008/05/30 11:24:01
  • Location: Zelenograd, Russia
  • Status: offline
RE: PIC24FJ128GA006 : Undefined reference to main 2009/10/20 08:51:55 (permalink)
0
.global  __main is needed if one wants to use the precompiled RAM data and registers initialization code as atsoft noted above.
#6
asmeng
New Member
  • Total Posts : 24
  • Reward points : 0
  • Joined: 2017/08/18 07:50:35
  • Location: 0
  • Status: offline
Re: RE: PIC24FJ128GA006 : Undefined reference to main 2017/08/23 10:25:23 (permalink) ☄ Helpfulby bmwman91 2018/11/25 19:47:46
0
MBedder
Add the following lines to your code:


.include        "p24xxxx.inc"   ; Include chip definitions

.global __reset ; Tell the linker where your code starts

.text           ; Start a code section

__reset:        ; A mandatory label. Note the double underscore
; Place your code here

.end            ; End of program. Place an empty string after this directive to avoid warning




I was having the same problem as the original poster and my code is building successfully after adding that code. Thanks for the help! How do you know which directives to use when? I looked in the XC16 Assembler User Guide and the explanations are difficult to understand for a beginner and there aren't many practical examples.
#7
PeterAwsmtek
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2016/12/03 17:41:34
  • Location: 0
  • Status: offline
Re: RE: PIC24FJ128GA006 : Undefined reference to main 2019/05/18 04:31:04 (permalink)
0
Hello!
I have similar problem but with XC16 compiler while porting Contiki OS to PIC24FJ.
I cant get where is entry point has specified.
Here is building system with make and it has a lot of make files so I decided to not post until someone ask.
I am sure that file containing main function added to source group.
But there is no presence of main function in the *.map file.
Please help!
 
 
#8
LdB_ECM
Junior Member
  • Total Posts : 56
  • Reward points : 0
  • Joined: 2019/04/16 22:01:25
  • Location: 0
  • Status: offline
Re: RE: PIC24FJ128GA006 : Undefined reference to main 2019/05/18 06:29:14 (permalink)
0
The entry point is set in your platform directory you made for the port and defined along with the makefile.
 
Did you read the actual documentation on porting?
No-one can really help you without knowing what you makefile does.
#9
LdB_ECM
Junior Member
  • Total Posts : 56
  • Reward points : 0
  • Joined: 2019/04/16 22:01:25
  • Location: 0
  • Status: offline
Re: RE: PIC24FJ128GA006 : Undefined reference to main 2019/05/18 06:34:40 (permalink)
0
Oh I should add you might like to look at the FreeRTOS port because it will do all the basics like setup the context switch timer and provide the context switch functions.
#10
PeterAwsmtek
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2016/12/03 17:41:34
  • Location: 0
  • Status: offline
Re: RE: PIC24FJ128GA006 : Undefined reference to main 2019/05/18 09:50:26 (permalink)
0
Hello, LdB_ECM!
Thanks for answer.
This is my error:
 
/opt/microchip/xc16/v1.36/bin/bin/../../lib/liblega-pic30-elf.a(crt0_standard.o)(.init+0x34): In function `L13':
: undefined reference to `_main'
/opt/microchip/xc16/v1.36/bin/bin/../../lib/liblega-pic30-elf.a(crt0_standard.o)(.init+0x36): In function `L13':
: undefined reference to `_main'
 
This is Makefile.cpu:
#
# Makefile for pic24fMX795F512L
# @author Peter Borisenko < peter@awsmtek.com>
#
# @file Makefile.pic24f
#

pic24f_MODEL=24FJ128GA010
CFLAGS += -O1 -fno-strict-aliasing -Wall -I /opt/microchip/xc16/latest/support/PIC24F/h/ $(CONTIKI_PLAT_DEFS)
CFLAGS += -ffunction-sections

### Define the CPU directory
CONTIKI_CPU=$(CONTIKI)/cpu/pic24f

### Define the cpu dirs and source files
CONTIKI_CPU_DIRS = . lib

CPU_LIBS = $(notdir $(wildcard $(CONTIKI_CPU)/lib/*.c))

CONTIKI_SOURCEFILES += pic24f.c clock.c watchdog.c rtimer-arch.c $(CPU_LIBS) debug-uart.c slip-uart.c

### Compiler definitions
CC       = xc16-gcc
LD       = xc16-gcc
AS       = xc16-as
AR       = xc16-ar
OBJCOPY  = xc16-objcopy
STRIP    = xc16-strip

ifneq ($(pic24f_MODEL),)
CFLAGS += -mcpu=$(pic24f_MODEL)
LDFLAGS += -mcpu=$(pic24f_MODEL) -T p$(pic24f_MODEL).gld -Wl,-Map=contiki-$(TARGET).map -s
LDFLAGS += -Wl,--defsym,_min_stack_size=4096 -Wl,--gc-sections
endif

### Compilation rules

%.so: $(OBJECTDIR)/%.o
    $(LD) -shared -o $@ $^

ifdef CORE
.PHONY: symbols.c symbols.h
symbols.c symbols.h:
    $(NM) -C $(CORE) | grep -v @ | grep -v dll_crt0 | awk -f $(CONTIKI)/tools/mknmlist > symbols.c
else
symbols.c symbols.h:
    cp ${CONTIKI}/tools/empty-symbols.c symbols.c
    cp ${CONTIKI}/tools/empty-symbols.h symbols.h
endif

contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o}
 
This is Makefile.platform:
ifndef CONTIKI
  $(error CONTIKI not defined! You must specify where CONTIKI resides!)
endif

ifdef DEVICE_ID
CFLAGS += -DDEVICE_ID=${DEVICE_ID}
endif

MCU = pic24f

CONTIKIDIRS += ${addprefix $(CONTIKI)/core/, net/mac net/mac/sicslowmac . }

CONTIKI_TARGET_DIRS = . dev apps net
CONTIKI_CORE = contiki-explorer16
CONTIKI_TARGET_MAIN = ${addprefix $(OBJECTDIR)/,${CONTIKI_CORE}.o}

CONTIKI_PLAT_DEFS += -D __USE_TIMER__

ifndef PIC24_TIMER_CLOCK
CONTIKI_PLAT_DEFS += -D __USE_TIMER_1__ -D PIC24_TIMER_CLOCK=1
endif
ifeq ($(PIC24_TIMER_CLOCK),1)
CONTIKI_PLAT_DEFS += -D __USE_TIMER_1__ -D PIC24_TIMER_CLOCK=1
endif
ifeq ($(PIC24_TIMER_CLOCK),2)
CONTIKI_PLAT_DEFS += -D __USE_TIMER_2__ -D PIC24_TIMER_CLOCK=2
endif
ifeq ($(PIC24_TIMER_CLOCK),3)
CONTIKI_PLAT_DEFS += -D __USE_TIMER_3__ -D PIC24_TIMER_CLOCK=3
endif
CONTIKI_CORE_SOURCEFILES = slip.c

CONTIKI_TARGET_SOURCEFILES += contiki-explorer16-main.c init-net.c
CONTIKI_TARGET_SOURCEFILES += leds-arch.c
CONTIKI_TARGET_SOURCEFILES += $(CONTIKI_CORE_SOURCEFILES)

CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)

CONTIKIPIC = $(CONTIKI)/cpu/$(MCU)
CONTIKIBOARD = .

include $(CONTIKIPIC)/Makefile.$(MCU)

MODULES += core/net core/net/mac core/net/llsec
# core/net/rime


 
Sorry for flat formatting. I get an access error when trying to post with "core" tag...
 
#11
LdB_ECM
Junior Member
  • Total Posts : 56
  • Reward points : 0
  • Joined: 2019/04/16 22:01:25
  • Location: 0
  • Status: offline
Re: RE: PIC24FJ128GA006 : Undefined reference to main 2019/05/18 21:02:31 (permalink)
0
That makefile is a mess what is the target on the command line, as in what is the command line ......  make ?????
 
The issue looks like CONTIKI_SOURCEFILES is not being compiled for the target .. you add a whole pile of file to it but do nothing with it
 
Generally I would expected a rule for  CONTIKI_SOURCEFILES ... something like
 
$(OBJECTDIR)/%.o: $(CONTIKI_SOURCEFILES)/%.c   
    $(CC) -g $(CFLAGS) -c  $< -o $@
 
It may be easier to do this on the IDE as you seem to be struggling with makefiles. Just add all those files in the CONTIKI_SOURCEFILES list into the source files on the IDE and try to build at least that will get you a start.
 
post edited by LdB_ECM - 2019/05/18 21:07:57
#12
PeterAwsmtek
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2016/12/03 17:41:34
  • Location: 0
  • Status: offline
Re: RE: PIC24FJ128GA006 : Undefined reference to main 2019/05/19 03:58:45 (permalink)
0
> Did you read the actual documentation on porting?
The Contiki porting guide I am able to find in internet is not actual. I use Contiki 3.2.
 
> Oh I should add you might like to look at the FreeRTOS port because it will do all the basics like setup the context switch timer and provide the context switch functions.
 
I have ever ported FreeRTOS. There is no problem to write system specific methods. The problem as I think in linker and/or compiler options. Since I've never worked with xc compilers directly (without MPLAB).
 
> That makefile is a mess what is the target on the command line, as in what is the command line ......  make ?????
I warned you )
 
Build command is "make TARGET=explorer16"
The project has two more makefiles. Project makefile just specifies contiki location and includes systemwise contiki makefile which stays unchanged. so I didnt publish it.
 
> The issue looks like CONTIKI_SOURCEFILES is not being compiled for the target .. you add a whole pile of file to it but do nothing with it
 
I see the line "CC contiki-explorer16-main.c" in the build log. This file contains main() function.
 
> It may be easier to do this on the IDE as you seem to be struggling with makefiles. Just add all those files in the CONTIKI_SOURCEFILES list into the source files on the IDE and try to build at least that will get you a start.
 
That was my idea first. But I want to learn as well as have a result.
#13
LdB_ECM
Junior Member
  • Total Posts : 56
  • Reward points : 0
  • Joined: 2019/04/16 22:01:25
  • Location: 0
  • Status: offline
Re: RE: PIC24FJ128GA006 : Undefined reference to main 2019/05/19 05:02:07 (permalink)
0
Where does it put the output of the line that compiles ontiki-explorer16-main.c?
It obviously isn't on the linker include because it can't find the resultant .o file produced.
 
I would make sure all the produced .o files go to the same build directory and make sure that directory is on the linker command include.
 
I am struggling to help more because obviously you have only part of the makefile process the linker part is missing totally
You have for example linker flags (LDFLAGS) but it isn't used anywhere you show
 
Can I suggest a makefile like this is much easier to use and understand .. each line is explained.
https://github.com/LdB-EC...e/blob/master/Makefile
make all   ... will make your elf and binary
make clean  ... will cleanup temp files when you want a full build
post edited by LdB_ECM - 2019/05/19 06:38:48
#14
PeterAwsmtek
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2016/12/03 17:41:34
  • Location: 0
  • Status: offline
Re: RE: PIC24FJ128GA006 : Undefined reference to main 2019/05/19 07:54:42 (permalink)
0
> Where does it put the output of the line that compiles ontiki-explorer16-main.c?
I am building it with sublime text:
mkdir obj_explorer16
  CC        ../../../apps/er-coap/er-coap.c
  CC        ../../../apps/er-coap/er-coap-engine.c
In file included from ../../../apps/er-coap/er-coap-engine.h:47:0,
                 from ../../../apps/er-coap/er-coap-engine.c:43:
../../../apps/er-coap/er-coap-observe-client.h:57:2: warning: #warning "COAP_MAX_OPEN_TRANSACTIONS smaller than COAP_MAX_OBSERVEES: " "this may be a problem"
  CC        ../../../apps/er-coap/er-coap-transactions.c
  CC        ../../../apps/er-coap/er-coap-observe.c
  CC        ../../../apps/er-coap/er-coap-separate.c
  CC        ../../../apps/er-coap/er-coap-res-well-known-core.c
In file included from ../../../apps/er-coap/er-coap-engine.h:47:0,
                 from ../../../apps/er-coap/er-coap-res-well-known-core.c:40:
../../../apps/er-coap/er-coap-observe-client.h:57:2: warning: #warning "COAP_MAX_OPEN_TRANSACTIONS smaller than COAP_MAX_OBSERVEES: " "this may be a problem"
  CC        ../../../apps/er-coap/er-coap-block1.c
  CC        ../../../apps/er-coap/er-coap-observe-client.c
In file included from ../../../apps/er-coap/er-coap-observe-client.c:44:0:
../../../apps/er-coap/er-coap-observe-client.h:57:2: warning: #warning "COAP_MAX_OPEN_TRANSACTIONS smaller than COAP_MAX_OBSERVEES: " "this may be a problem"
  CC        ../../../apps/rest-engine/rest-engine.c
  CC        ../../../platform/explorer16/./contiki-explorer16-main.c
..... Plenty of other C files ......
  CC        ../../../core/net/llsec/nullsec.c
  CC        symbols.c
  AR        contiki-explorer16.a
  CC        test_1.c
  LD        test_1.explorer16
/opt/microchip/xc16/v1.36/bin/bin/../../lib/liblega-pic30-elf.a(crt0_standard.o)(.init+0x34): In function `L13':
: undefined reference to `_main'
/opt/microchip/xc16/v1.36/bin/bin/../../lib/liblega-pic30-elf.a(crt0_standard.o)(.init+0x36): In function `L13':
: undefined reference to `_main'
 
> Generally I would expected a rule for  CONTIKI_SOURCEFILES ... something like
I tried this as well. I have found that build folder contains just dependency files (*.d), no object files in there...
#15
PeterAwsmtek
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2016/12/03 17:41:34
  • Location: 0
  • Status: offline
Re: RE: PIC24FJ128GA006 : Undefined reference to main 2019/05/19 08:17:10 (permalink)
0
> I am struggling to help more because obviously you have only part of the makefile process the linker part is missing totally
You have for example linker flags (LDFLAGS) but it isn't used anywhere you show
 
It's not missing. The rules is in the systemwise Makefile:
https://gist.github.com/D...b11f0218dc9088d5fa535a
 
#16
Jump to:
© 2019 APG vNext Commercial Version 4.5