Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

Building a Linux Application Project

Hi fellows ,

I want to build a Linux Application on NIOS 1c12 evaluation kit using NIOS IDE 5.0

My project has got 2 files : main.c and add.c

In main.c :

int main()

{

int a , b;

a = 5 ;

b = 7 ;

printf("%d + %d = %d" , a , b , add( a,b ));

return 0;

}

In add.c :

int add( int a , int b )

{

return ( a + b );

}

There are 2 actions I should do : Build Make Target and Build Project. Is it true ?

For "Build Make Target" , here are my steps :

- Choose Build Make Target from the context menu after right-clicking my project folder in NIOS IDE

- In "Make Target" window , I choose "Add"

- I enter the string "main" in "Target Name" and "Make Target" fields , then OK

- Then Build

- I got this error message :

make -k mp3e_main

gcc mp3e_main.c -o mp3e_main

make: *** [mp3e_main] Error 255

For "Build Project" , I got the following error :

make -k all

make: *** No rule to make target `all'.

My question :

Could you please show me the ORDER of these actions and details of each one ?

Any helps would be much appreciated.

Quan

6 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Read the tutorials and everything will be alright. And also take a look at code examples. Everything is explained. The only thing to do is to review the documentation.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks HelmChen for your reply.

    After uploading my application to NIOS uClinux , I want to debug my application but *.gdb hasn't been created in NIOS IDE.

    I added this code to Makefile as the document suggests but nothing happened :

    CFLAGS += -O0 –g

    all: app.exe app.gdb …

    What should I do to create that *.gdb ?

    Regards,

    Quan
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    If you do it like in the examples, you don't to add a line: Set DEBUG=1 in the makefile.

    But i don't know how your Makefile looks like...
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi ,

    This is my "makefile" :

    --------------------------------------------------------------------------------------------

    # # configurable options# - set DEBUG = 1 to turn on debugging support#

    DEBUG = 1

    PROJ_NAME = myapp

    INSTALL_DIR =

    PROGS := $(PROJ_NAME).exe# CFLAGS +=

    cflags += -o0 -g

    # # You should not need to modify anything beyond this point#

    TOPDIR = .

    include $(TOPDIR)/Rules.mak

    ifeq '$(DEBUG)' '1'

    PROGS += $(PROGS:.exe=.gdb)

    endif

    # all: $(PROGS)

    all: myapp.exe myapp.gdb

    .PHONY: clean

    clean:

    -rm -f *.[oad] *.elf *.gdb *.bin *.exe

    .PHONY: install

    install: all

    ifeq "$(INSTALL_DIR)" ""

    $(error No installation directory specified)

    endif

    mkdir -p $(INSTALL_DIR)/bin

    install -v $(filter %.exe, $(PROGS)) $(INSTALL_DIR)/bin

    ----------------------------------------------------------------------------------------------

    I can easily create a gdb and debug my HelloWorld application with this makefile, but when I use this for a bigger one of mine , I cannot create it.

    I tried to remove ".PHONY: clean ... " but things are not better

    This is "Rules.mak" :

    ----------------------------------------------------------------------------------------------

    # ########################################################################## Variables and Rules for building Nios II Linux applications# # This file is a "template" that is copied over from the Nios II Linux# Application plug-in. This file should be included within your top-level# Makefile.#

    ifeq "$(origin TOPDIR)" "undefined"

    TOPDIR := $(shell pwd)

    endif

    # # The Settings.mak file is automatically generated by Eclipse. It# contains values for all external variables used by this Makefile# fragment.# # The "dash" in front of the include statement indicates that the Make# process will not terminate if it cannot find the Settings.mak file.#

    -include $(TOPDIR)/Settings.mak

    # This turns on various levels of hardware multiply support# Set the following option to none, mul, or mulx# none := no hardware multiplication support at all# mul := supports use of the mul assembler instruction# mulx := supports use of the mul and mulx assembler instruction

    ifeq "$(HW_MUL_SUPPORT)" ""

    HW_MUL_SUPPORT := mulx

    endif

    # # Warn users if external variables have not yet been defined.#

    ifeq "$(origin UTILSDIR)" "undefined"

    $(warning The location of the utiltiies directory is undefined)

    endif

    ifeq "$(origin LIBCDIR)" "undefined"

    $(warning The location of uClibc is undefined)

    endif

    # # Path + Name of necessary executables#

    EXECSUFFIX := .exe

    CROSS := nios2-elf-

    CC := $(CROSS)gcc

    AR := $(CROSS)ar

    LD := $(CROSS)ld

    NM := $(CROSS)nm

    RANLIB := $(CROSS)ranlib

    STRIPTOOL := $(CROSS)strip

    ELF2FLT := $(UTILSDIR)/bin/elf2flt

    # # Location of important files#

    CRT0 := $(LIBCDIR)/lib/crt0.o

    LIBC := $(LIBCDIR)/lib/libc.a

    LIBGCC := $(shell $(CC) -print-file-name=libgcc.a)

    LIBM := $(shell $(CC) -print-file-name=libm.a)

    LIBGCCDIR := $(dir $(LIBGCC))

    LINKSCRIPT := $(UTILSDIR)/scripts/elf2flt.ld

    # # Various flags, modifications are not recommended and not necessarily# supported.# # DEPFLAGS:# -MM : ignore system includes, # -M : include system includes in the dependency#

    WARNING_FLAGS := -Wall

    # basic C flags to pass to the compiler

    CFLAGS += -nostdinc -D__linux__

    # if DEBUG is turned on, then turn off optimizations and turn on symbol# generation, else turn on level 2 optimizations

    ifeq ($(DEBUG),1)

    CFLAGS += -O0 -g

    else

    CFLAGS += -O2

    endif

    # pass any additional include directories to the compiler while building the# application

    CFLAGS += -I$(LIBCDIR)/include -I$(LIBGCCDIR)/include

    # Temporary workaround for nios2-elf-gcc bug# First noticed in v3.4.1 (Altera Nios II 1.1 b131)# To be removed at a later date when bug is resolved.

    CFLAGS += -fno-optimize-sibling-calls

    # Turn on the various levels of hardware multiplication support.

    ifeq ($(strip $(HW_MUL_SUPPORT)),none)

    CFLAGS += -mno-hw-mul -mno-hw-mulx

    endif

    ifeq ($(strip $(HW_MUL_SUPPORT)),mul)

    CFLAGS += -mhw-mul -mno-hw-mulx

    endif

    ifeq ($(strip $(HW_MUL_SUPPORT)),mulx)

    CFLAGS += -mhw-mul -mhw-mulx

    endif

    mulx_help_text := $(shell $(CC) --target-help | grep mulx)

    ifeq "$(mulx_help_text)" ""

    CFLAGS := $(filter-out -mhw-mulx -mno-hw-mulx, $(CFLAGS))

    endif

    DEPFLAGS = -E -MM

    LDFLAGS := -msys-crt0=$(CRT0) -r -d -L$(LIBCDIR)/lib

    LDLIBS := $(LIBM) $(LIBGCC) $(LIBC)

    # relocate the absolute elf file if requested

    ifneq ($(TEXT),)

    TEXT_LOC_OPT := -Ttext $(TEXT)

    endif

    ifneq ($(DATA),)

    DATA_LOC_OPT := -Tdata $(DATA)

    endif

    ifneq ($(BSS),)

    BSS_LOC_OPT := -Tbss $(BSS)

    endif

    # default stack size is 4K

    FLTFLAGS:=

    %.exe : %.flt

    cp -f $< $@

    # # Make a relocatable flat file from an ELF file.# STACKSIZE is defined by individual makefiles.#

    %.flt : %.elf

    $(ELF2FLT) $(FLTFLAGS) -o $@ $<

    # # Make a bound-address ELF file required by GDB for debugging the application.#

    %.gdb : %.bin FORCE

    $(LD) -T $(LINKSCRIPT) $(TEXT_LOC_OPT) $(DATA_LOC_OPT) $(BSS_LOC_OPT) -o $@ $<

    # # Make a relocatable ELF file.#

    %.elf : %.bin

    $(LD) -T $(LINKSCRIPT) -Ur -o $@ $<

    # # Standard stuff: The object file is dependent on the C source and Makefile timestamps#

    %.o : %.c Makefile

    $(CC) $(CFLAGS) $(WARNING_FLAGS) -c -o $@ $<

    %.o : %.cpp Makefile

    $(CC) $(CFLAGS) $(WARNING_FLAGS) -o $@ $<

    %.bin : %.o

    $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)

    # # Automatically generate dependencies for the .c source files.# Be sure to omitt debug-level flags as this can produce macro def&#39;n output.# The sed "script" makes the .d (in addition to the .c) file a# target of the dependencies so that the .d file is rebuild if required.# e.g. "X.o: <dependency-list>" gets transformed into "X.o X.d: <dependency-list>"#

    %.d: %.c

    $(SHELL) -ec &#39;$(CC) $(DEPFLAGS) $(CFLAGS) -c $< | sed &#39;\&#39;&#39;s/\($*\)\.o[ :]*/\1.o $@ : /g&#39;\&#39;&#39; >$@; [ -s $@ ] || rm -f $@&#39;

    FORCE: ;

    ----------------------------------------------------------------------------------------------

    I tried to remove "rm -f ..." (letters in bold) but *.gdb is still not made.

    It seems to me that *.gdb has made but was removed somewhere before makefile & Rules.mak complete.

    What do you think ?

    Quan
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Well,

    i didn&#39;t test your files, yet. But in my firstlook I&#39;m wondering where do you tell the compiler to compile your source files?

    With the &#39;Hello&#39; Makefile you must have a toplevel c-source, which name is equal to your project name. In your case: myapp.c.

    Look again at the variable PROJ_NAME and PROGS in the makefile.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    HelmChen,

    Actually , the above makefile is taken from the Hello application which can be found in : C:\altera\kits\nios2\examples\software\linux\apps\samples\hello

    and this Hello project doesn&#39;t need SOURCE specified. When I tried this project , everything was fine : it could create *.gdb for me to debug , run , watch variable ,..... with it.

    My app and project names are the same. Anyway , I tried to add "SOURCE : file1.c file2.c file3.c" to my REAL project , which is much larger than hello app , but it could not create *.gdb although object file was created beautifully. I doubted at some "rm ..." commands in makefile and Rules.mak and tried to comment them out but it seemed that the "Build Make Target" didn&#39;t understand my changes. I am also thinking of NIOS 1C12 memory availability for my app (main is ~123772bytes , main.o is ~40200bytes).

    Is memoy the problem of mine ?

    What do you think ?

    Quan