Search

Technical Discussion Group Forum

This forum is provided for user discussion. While Beacon EmbeddedWorks support staff and engineers participate, Beacon EmbeddedWorks does not guarantee the accuracy of all information within in the Technical Discussion Group (TDG).

The "Articles" forums provide brief Articles written by Beacon EmbeddedWorks engineers that address the most frequently asked technical questions.

To receive email notifications when updates are posted for a Beacon EmbeddedWorks product download, please subscribe to the TDG Forum of interest.

TDG Forum

PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 27 Oct 2005 07:49 AM by  peter.barada@logicpd.com
How to compile and link a ".c" program??
 7 Replies
Sort:
You are not authorized to post a reply.
Author Messages
sailqiu@163.com
New Member
New Member
Posts:


--
25 Oct 2005 07:32 PM
    I am just get LH79520 and I have run the Embedix linux
    Now I compile my program in redhat linux, and I have unzip gnuarm_linux.tar.gz to redhat linux
    But I don't know how to use gnuarm_linux tools, and how to compile and link my program runing in Embedix linux

    Please give me a sample
    or
    tell me where can I get the referrence

    Thanks
    sailqiu@163.com
    New Member
    New Member
    Posts:


    --
    25 Oct 2005 10:04 PM
    I tried but failed....

    ++++++++++++++++++++++++++++
    # arm-elf-gcc -Wall -O2 -elf2flt -c test2.c
    # arm-elf-objdump test2.o -x

    test2.o: file format elf32-littlearm
    test2.o
    architecture: arm, flags 0x00000011:
    HAS_RELOC, HAS_SYMS
    start address 0x00000000
    ???? = 0: [APCS-32]

    Sections:
    Idx Name Size VMA LMA File off Algn
    0 .text 00000014 00000000 00000000 00000034 2**2
    CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
    1 .data 00000000 00000000 00000000 00000048 2**0
    CONTENTS, ALLOC, LOAD, DATA
    2 .bss 00000000 00000000 00000000 00000048 2**0
    ALLOC
    3 .comment 00000012 00000000 00000000 00000048 2**0
    CONTENTS, READONLY
    SYMBOL TABLE:
    00000000 l df *ABS* 00000000 test2.c
    00000000 l d .text 00000000
    00000000 l d .data 00000000
    00000000 l d .bss 00000000
    00000000 l d .comment 00000000
    00000000 g F .text 00000014 main


    RELOCATION RECORDS FOR [.text]:
    OFFSET TYPE VALUE
    00000010 R_ARM_PC24 .text

    [root@localhost root]# arm-elf-ld test2.o
    arm-elf-ld: warning: cannot find entry symbol _start; defaulting to 00008000
    ++++++++++++++++++++++++++++

    What's happened?
    sailqiu@163.com
    New Member
    New Member
    Posts:


    --
    25 Oct 2005 10:23 PM
    +++++++++++++++++++++
    arm-elf ld hello.o -e 0x00000000

    download it to Embedix linux and run
    but get this message "Segmentation fault"
    peter.barada@logicpd.com
    New Member
    New Member
    Posts:72


    --
    26 Oct 2005 09:57 AM
    > I tried but failed....
    >
    > ++++++++++++++++++++++++++++
    > # arm-elf-gcc -Wall -O2 -elf2flt -c test2.c
    > # arm-elf-objdump test2.o -x

    You've compiled test2.c into an object file, but you haven't linked it so arm-elf-objdump shows you a dump of just the object file, and not a fully-linked program. Try:

    # arm-elf-gcc -Wall -O2 -elf2flt -c test2.c
    # arm-elf-gcc -o test2 test2.o -Wl,-Map test2.map
    # arm-elf-objdump test2 -x

    the 'arm-elf-gcc -o test2 test2.o' will link test2.o with the standard startup files and create a full-linked executable. the '-wl,-Map test2.map' instructs the linke to create a linker map file which will show what is linked with test2.o
    sailqiu@163.com
    New Member
    New Member
    Posts:


    --
    26 Oct 2005 08:29 PM
    I tried follow you:

    ++++++++++++++++++++++++++
    #arm-elf-gcc test2.c -c -Wall -elf2flt -O2
    #arm-elf-ld test2.o -o test2 -Map test.map
    arm-elf-ld:warning:cannot find entry symbol _start:defaulting to 0x00008000
    #arm-elf-ld test2.o -o test2 -Map test.map -entry 0x00008000
    and
    result of executing in Embedix linux: "segmentation fault"

    //test.map start
    Memory Configuration

    Name Origin Length Attributes
    *default* 0x00000000 0xffffffff

    Linker script and memory map

    LOAD test2.o
    0x00008000 .=0x8000
    .
    .
    .

    .stack 0x00080000 0x0
    0x00080000 _stack=.
    *(.stack)
    OUTPUT(test2 elf32-littlearm)
    //test.map end
    +++++++++++++++++++++++

    I puzzled what's wrong with it
    Why is the result always "Segmentation fault"?
    How can I creat a correct binary file to run on the Embedix linux?
    peter.barada@logicpd.com
    New Member
    New Member
    Posts:72


    --
    26 Oct 2005 08:44 PM
    >I tried follow you:
    >
    >++++++++++++++++++++++++++
    >#arm-elf-gcc test2.c -c -Wall -elf2flt -O2
    >#arm-elf-ld test2.o -o test2 -Map test.map
    >arm-elf-ld:warning:cannot find entry symbol _start:defaulting to 0x00008000

    you need to use 'arm-elf-gcc -o test2 test2.o' to link your program since the compiler invokes the linker with other libraries and startup code necessary for your program to run.

    Please see my previous message and try the commands I gave there.
    sailqiu@163.com
    New Member
    New Member
    Posts:


    --
    27 Oct 2005 06:33 AM
    first I tried follow you, but it doesn't work

    ++++++++++++++++++++++++
    arm-elf-gcc -o hello hello.c -O2
    /usr/bin/../lib/gcc-lib/arm-elf/3.2.1/../../../../arm-elf/bin/ld: cannot open crt0.o: ?????????
    collect2: ld returned 1 exit status

    # arm-elf-gcc -Wall -O2 -elf2flt -c hello.c
    # arm-elf-gcc -o hello hello.o -Wl,-Map hello.map -nostdlib
    It can create the "hello" binary file
    but it doesn't work normally,print disordered code
    +++++++++++++++++++++++++
    Can anyone show me a whole process from assembly to linking, correct running.
    Is there any problems in my compile environment?
    peter.barada@logicpd.com
    New Member
    New Member
    Posts:72


    --
    27 Oct 2005 07:49 AM
    Wait a minute. You are trying to build a program to run on a "linux" system?

    If so, then you want to use arm-linux-gcc compiler, not the arm-elf-gcc compiler.
    This is because the arm-linux compiler is configured to us relocatable code, and to link in particualar startup files to handle initializion and exit correctly.

    Tray instead:

    # arm-linux-gcc -O -Wall -c test2.c
    # arm-linux-gcc -o test2 test2.o -Wl,-Map test2.map

    Which should produce test2 which should run on your LH79520 linux board(assuming the linux tools were properly configured).
    You are not authorized to post a reply.