Trouble compiling and linking a simple app

Chris Johns chrisj at rtems.org
Wed Sep 3 22:51:52 UTC 2014


On 4/09/2014 7:49 am, Ricardo Derbes wrote:
> Hello, this is a newbie's question:

Welcome to rtems.

>
> I'm having trouble trying to build a test application using RTEMS
> 4.10.2 for a sparc (erc32) project.
> I have downloaded sparc-rtems-4.10 toolchain rpm's and installed them
> using yum on my OS (fedora20 x86-64), downloaded
> rtems-4.10.2 and ran bootstrap, configure & make install without a glitch.
> My configuration options are:
> --target=sparc-rtems4.10 \
> --disable-multiprocessing \
> --disable-posix \
> --disable-itron \
> --disable-networking \
> --disable-cxx \
> --enable-rtems-debug \
> --enable-tests \
> --enable-rtemsbsp=erc32 \
> --prefix=/home/dev/rtems/
> rtemsproduct_erc32 \
> CFLAGS_FOR_TARGET='-mcpu=cypress -g -O4'
>

Great.

>  From installed directory
> /home/dev/rtems/rtemsproduct_erc32/sparc-rtems4.10/erc32/lib, I've
> copied librtemscpu.a, librtemsbsp.a, linkcmds, linkcmds.base,
> start.o and include/ directory to my workspace lib/ directory

Why copy these files ? Why not use the files in the path RTEMS installed 
them ?

If you copy the files you create a configuration management issue for 
you and your development team, eg if RTEMS is updated have all the 
copies been updated. A build system should be able to manage the 
compiling and linking process with the files in the installed tree.

>
> I wrote a short test application:
>
> #define CONFIGURE_INIT
> #include "system.h"
> #include <stdio.h>
> rtems_task Init(rtems_task_argument ignored)
> {
>      uint32_t count = 0;
>      while(1)
>      {
>          printf("%lu: Hello world, I'm an erc32 application!  \n", count);
>          count++;
>          rtems_task_wake_after(100);
>      }
>      rtems_task_delete(RTEMS_SELF);
> }
>
> where system.h is:
>
> #include <rtems.h>
> #include <bsp.h>
>
> #ifndef SYSTEM_H_
> #define SYSTEM_H_
>
> #define STACK_SIZE_MULTIPLIER 2
> #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
> #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
> #define CONFIGURE_MAXIMUM_TASKS             11
> #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES    20
> #define CONFIGURE_MAXIMUM_SEMAPHORES        25
> #define CONFIGURE_MAXIMUM_PARTITIONS        1
> #define CONFIGURE_MAXIMUM_PERIODS           10
> #define CONFIGURE_MICROSECONDS_PER_TICK     10000
> #define CONFIGURE_EXTRA_TASK_STACKS         (CONFIGURE_MAXIMUM_TASKS *
> ((RTEMS_MINIMUM_STACK_SIZE *
> STACK_SIZE_MULTIPLIER)-RTEMS_MINIMUM_STACK_SIZE))
> #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
> #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
> #define CONFIGURE_APPLICATION_DISABLE_FILESYSTEM
>
> #include <rtems/confdefs.h>
> rtems_task Init(rtems_task_argument argument);
> #endif /* SYSTEM_H_ */
>
>
> Compilation -> raises some warnings:
> sparc-rtems-gcc -I../lib/include -O0 -g3 -Wall -Wextra -c
> -fmessage-length=0 -MMD -MP -MFmain.d -MTmain.d -o main.o ../main.c
> In file included from ../lib/include/rtems/score/object.h:898,
>                   from ../lib/include/rtems/rtems/types.h:28,
>                   from ../lib/include/rtems.h:50,
>                   from ../system.h:7,
>                   from ../main.c:8:
> ../lib/include/rtems/score/object.inl: In function '_Objects_Is_local_id':
> ../lib/include/rtems/score/object.inl:165: warning: unused parameter 'id'
> ../lib/include/rtems/score/object.inl: In function '_Objects_Open_string':
> ../lib/include/rtems/score/object.inl:337: warning: unused parameter 'name'
> ../main.c: In function 'Init':
> ../main.c:12: warning: unused parameter 'ignored'
>
> Linking:
> sparc-rtems-gcc -L/opt/rtems-4.10/lib/gcc/sparc-rtems4.10/4.4.7
> -L/opt/rtems-4.10/sparc-rtems4.10/lib -L../lib -T ../lib/linkcmds -e
> start -Wl,--start-group -lgcc -lrtemscpu -lrtemsbsp -Wl,--end-group -o
> erc32Project  ./main.o ../lib/start.o

There is a lot going on to link an RTEMS application and some things 
depend on the BSP. Currently you need to use the bsp_specs file. There 
is no easy way around this unless you dig very deep into the whole 
process. The issues relate to the runtime start files and some 
dependences between various libraries and I suspect this is what you are 
seeing in your errors.

I suggest you start with the examples-v2 repo and the README's in it. 
Clone the repo and build the examples against your installed BSP. You 
can then look at the command lines to the compile and link code and base 
your build environment on how it is done in the examples.

FYI the examples-v2 contains a waf build system which uses the pkgconfig 
file in the BSP to obtain the needed CFLAGS and LDFLAGS. If you try this 
and add '--show-commands' to the configure command you will see the 
build commands and can copy them. If you decide to use waf you can just 
copy an example and use it as the base for your application.

Chris

> ./main.o: In function `Init':
> /home/dev/workspace/erc32Project/Debug/../main.c:19: undefined
> reference to `rtems_task_wake_after'
> ./main.o:(.data+0x20): undefined reference to `bsp_boot_cmdline'
> ./main.o:(.data+0x24): undefined reference to `console_initialize'
> ./main.o:(.data+0x28): undefined reference to `console_open'
> ./main.o:(.data+0x2c): undefined reference to `console_close'
> ./main.o:(.data+0x30): undefined reference to `console_read'
> ./main.o:(.data+0x34): undefined reference to `console_write'
> ./main.o:(.data+0x38): undefined reference to `console_control'
> ./main.o:(.data+0x3c): undefined reference to `Clock_initialize'
> ./main.o:(.data+0x54): undefined reference to `newlib_create_hook'
> ./main.o:(.data+0x60): undefined reference to `newlib_delete_hook'
> ./main.o:(.data+0xc0): undefined reference to `bsp_idle_thread'
> ./main.o:(.data+0xec): undefined reference to
> `_RTEMS_tasks_Initialize_user_tasks_body'
> ../lib/start.o: In function `trap_table':
> /home/dev/rtems/rtems-4.10.2/c/src/lib/libbsp/sparc/erc32/../../sparc/shared/start.S:64:
> undefined reference to `window_overflow_trap_handler'
> /home/dev/rtems/rtems-4.10.2/c/src/lib/libbsp/sparc/erc32/../../sparc/shared/start.S:64:
> undefined reference to `window_overflow_trap_handler'
> /home/dev/rtems/rtems-4.10.2/c/src/lib/libbsp/sparc/erc32/../../sparc/shared/start.S:65:
> undefined reference to `window_underflow_trap_handler'
> /home/dev/rtems/rtems-4.10.2/c/src/lib/libbsp/sparc/erc32/../../sparc/shared/start.S:65:
> undefined reference to `window_underflow_trap_handler'
> ../lib/start.o: In function `CLOCK_SPEED':
> /home/dev/rtems/rtems-4.10.2/c/src/lib/libbsp/sparc/erc32/../../sparc/shared/start.S:158:
> undefined reference to `syscall'
> /home/dev/rtems/rtems-4.10.2/c/src/lib/libbsp/sparc/erc32/../../sparc/shared/start.S:158:
> undefined reference to `syscall'
> /home/dev/rtems/rtems-4.10.2/c/src/lib/libbsp/sparc/erc32/../../sparc/shared/start.S:160:
> undefined reference to `window_flush_trap_handler'
> /home/dev/rtems/rtems-4.10.2/c/src/lib/libbsp/sparc/erc32/../../sparc/shared/start.S:160:
> undefined reference to `window_flush_trap_handler'
> ../lib/start.o: In function `zerobss':
> /home/dev/rtems/rtems-4.10.2/c/src/lib/libbsp/sparc/erc32/../../sparc/shared/start.S:333:
> undefined reference to `boot_card'
> collect2: ld returned 1 exit status
>
> In cannot find what I am doing wrong, please help
> Thank you very much
>
> Ricardo
> _______________________________________________
> users mailing list
> users at rtems.org
> http://lists.rtems.org/mailman/listinfo/users
>


More information about the users mailing list