Electropepper
Electropepper

Reputation: 11

Can't compile simple code with SDCC for pic on debian

I'm trying to compile the following code with SDCC, in Debian using only VIM and a Makefile:

void main(void) {

}

Yes, that simple, it's not working yet. I'm using a Makefile like this :

# GNU/Linux specific Make directives.

# Declare tools.
SHELL = /bin/sh
CC = sdcc 
LD = gplink 
ECHO = @echo

MCU = 16f88
ARCH = pic14

CFLAGS  = -m$(ARCH) -p$(MCU) 
LDFLAGS = -c -r -w -m I /usr/share/sdcc/lib/$(ARCH)/

EXECUTABLE = t1

SOURCES = test2.c 
OBJECTS = $(SOURCES:.c=.o)
CLEANFILES = test2.o test2.asm test2.map test2.lst

.SUFFIXES: .c .o
.PHONY: clean

# Compile
all: $(EXECUTABLE)

.c.o:
    $(AT) $(CC) $(CFLAGS) -o $*.o -c $<

$(EXECUTABLE): $(OBJECTS)
    $(AT) $(LD) $(LDFLAGS) $(OBJECTS) -o $(EXECUTABLE)

clean:
    $(AT) rm -rf $(CLEANFILES)

After all of this the output after running the makefile is:

sdcc  -mpic14 -p16f88  -o test2.o -c test2.c
gplink  -c -r -w -m I /usr/share/sdcc/lib/pic14/ test2.o -o t1
make: *** [t1] Segmentation fault

I have tried more complex code with the same result, I can't see what's wrong, anyone ?

Upvotes: 1

Views: 2086

Answers (1)

Diego Herranz
Diego Herranz

Reputation: 2947

I see several things that can be causing you problems:

  • When you compile for PICs using SDCC, you need the option --use-non-free because some PIC header files have a special Microchip Licence which is not GPL compatible. Furthermore, --use-non-free might not be available on Debian because of their freedom policy if you installed SDCC from repositories. You would need to install the latest SDCC from the official website.

  • On the linking stage, you should include the PIC libraries needed to run. Try executing sdcc -mpic14 -p16f88 --use-non-free -V test2.c. This way, SDCC links automatically and With -V (verbose) you can see the calls to assembler and linker and can see the libraries that are added on linkage.

Upvotes: 1

Related Questions