Altera_Forum
Honored Contributor
19 years agoReboot when running program with two .c files
I wrote a very simple test program that runs just fine:
int main(int argc, char *argv)
{
unsigned char *p = (unsigned char *) malloc(2048*sizeof(unsigned char));
printf("Allocation via malloc() succeeded\n");
free(p);
} I am not using the NIOS II IDE to build the application, rather I use a Makefile and build from the command line. I altered this test program every so slightly, by simply moving the code that appears in main to its own separate .c file, as shown below. test_malloc.c: extern void foo(void);
int main(int argc, char *argv)
{
foo();
} foo.c: #include <unistd.h># include <stdlib.h># include <stdio.h>
void foo()
{
unsigned char *p = (unsigned char *) malloc(2048*sizeof(unsigned char));
printf("Allocation via malloc() succeeded\n");
free(p);
} This builds, but when I run it I think I'm getting a crash. uClinux reboots - this is very strange, and I am wondering if it has something to do with my makefile and how I am linking things. Perhaps my arguments to elf2flt are incorrect? Any help would be most appreciated, and my Makefile follows. include ../Rules.mak
VERSION=$(shell cat ../../VERSION)
CFLAGS += $(INCLUDES) -O2 -nostdinc -Wall -DLINUX -g
SRC = test_malloc.c foo.c
OBJ = $(addsuffix .o, $(basename $(SRC)))
LIBDIRS += -L/cygdrive/c/Altera/kits/nios2_51/bin/eclipse/plugins/com.microtronix.nios2linux.uClibc_1.4.0/lib
LDFLAGS += -elf2flt
LIBS += -lc
all: test_malloc.exe
test_malloc.exe: $(OBJ) Makefile# $(CC) -o $@ $(OBJ) $(LIBDIRS) $(LIBS)# $(CC) $(CFLAGS) $< -o $@
install: all
cp test_malloc.exe /cygdrive/c/opt/toga/linux_root/home/
clean:
rm -f test_malloc.exe $(OBJ)
.PHONY: all install uninstall clean