Search code examples
cmakefilehyperlinkbuildrtems

using powf function in rtems (undefined reference to powf)


I'm trying to use powf function in an rtems application. When I call powf(a,b); inside Init() function, it compiles ok. But when I call powf in some other function, the compiler gives me 'undefined reference to powf' message even though I have those #include <math.h> and #include <float.h>. I event tried merging the file, but it is the same.

#define CONFIGURE_...
#define CONFIGURE_...
#include <rtems/confdefs.h>

rtems_task Init( rtems_task_argument ignored) 
{


powf(a,b); // ok

}

int my_other_func()
{

powf(c,d); // undefined reference error..

}

What can be the problem?

EDIT(ADD) : I added source code and makefile below. The compiled rtems OS package is specified by shell environment variable RTEMS_MAKEFILE_PATH.

Makefile :

include ../Makefile.base
_RAM_START = 0x60000000
XCFLAGS = -qnolinkcmds -T ../../lib/linkcmds.abts3 -D_RAM_START=$(_RAM_START)
XCFLAGS += -lm -DALDEBARAN_RTEMS

../Makefile.base :

#
#  RTEMS_MAKEFILE_PATH is typically set in an environment variable
#

PGM=${ARCH}/faster_rcnn.exe

# optional managers required
MANAGERS=all

# C source names

VPATH = ../src
VPATH += ../../../../abfrcnn/bare-c/lrn_layer

CSRCS = init.c
CSRCS += lrn_layer.c

CSRCS1 = $(notdir $(CSRCS))
COBJS_ = $(CSRCS1:.c=.o)

include $(RTEMS_MAKEFILE_PATH)/Makefile.inc
include $(RTEMS_CUSTOM)
include $(PROJECT_ROOT)/make/leaf.cfg
#XCFLAGS += -I../../include
COBJS = $(COBJS_:%=${ARCH}/%)

OBJS= $(COBJS) $(CXXOBJS) $(ASOBJS)

#all: ${ARCH} $(PGM) RUNTCL
all: ${ARCH} $(PGM)

$(PGM): $(OBJS)
    $(make-exe)

RUNTCL:
    echo 'system_init' > run.tcl
    echo 'load_image o-optimize/faster_rcnn.exe' >> run.tcl
    echo 'run $(_RAM_START)' >> run.tcl

clean:
    -$(RM) -r $(ARCH)

../src/init.c :

...
#include <math.h>

rtems_status Init(rtems_argument ignored)
{    
...
    printf(" pow(1.1,2.2) = %f\n", powf(1.1,2.2)); // <== powf compiles liks ok
    //zf_coco();

}

../../../../abfrcnn/bare-c/lrn_layer/lrn_layer.c

#include <stdio.h>
#include <math.h>

int lrn_layer(... args... )
{

 ...
            val = 1./powf((1.+a/(float)(k^2)*tmp),b); // method1
 ...
} // main ROI loop

The result of make command :

test -d o-optimize || mkdir o-optimize
sparc-ab-rtems-gcc --pipe -B/home/ckim/prj/abts/rtems-qt/rtems-4.10.99-kernel/build-rtems/rtems-package/sparc-ab-rtems/aldebaran2/lib/ -specs bsp_specs -qrtems   -Wall -qnolinkcmds -T ../../lib/linkcmds.abts3 -D_RAM_START=0x60000000 -lm -DALDEBARAN_RTEMS -O4    -mtune=v8 -msoft-float -fcommon -DTARGET_ALDEBARAN       -c   -o o-optimize/init.o ../src/init.c
../src/init.c:120:2: warning: missing braces around initializer [-Wmissing-braces]
  {0}, //   rtems_chain_control;
  ^
../src/init.c:120:2: warning: (near initialization for 'ald_sd_card_driver_table[0].queue.Chain') [-Wmissing-braces]
sparc-ab-rtems-gcc --pipe -B/home/ckim/prj/abts/rtems-qt/rtems-4.10.99-kernel/build-rtems/rtems-package/sparc-ab-rtems/aldebaran2/lib/ -specs bsp_specs -qrtems   -Wall -qnolinkcmds -T ../../lib/linkcmds.abts3 -D_RAM_START=0x60000000 -lm -DALDEBARAN_RTEMS -O4    -mtune=v8 -msoft-float -fcommon -DTARGET_ALDEBARAN       -c   -o o-optimize/lrn_layer.o ../../../../abfrcnn/bare-c/lrn_layer/lrn_layer.c
../../../../abfrcnn/bare-c/lrn_layer/lrn_layer.c: In function 'lrn_layer':
../../../../abfrcnn/bare-c/lrn_layer/lrn_layer.c:201:12: warning: 'w_idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  if (w_idx == w && h_idx == h) {
            ^
sparc-ab-rtems-gcc --pipe -B/home/ckim/prj/abts/rtems-qt/rtems-4.10.99-kernel/build-rtems/rtems-package/sparc-ab-rtems/aldebaran2/lib/ -specs bsp_specs -qrtems   -Wall -qnolinkcmds -T ../../lib/linkcmds.abts3 -D_RAM_START=0x60000000 -lm -DALDEBARAN_RTEMS -O4    -mtune=v8 -msoft-float -fcommon -DTARGET_ALDEBARAN      -L/opt/abde-rtems/lib/gcc/sparc-ab-rtems/4.8.2/soft -L/opt/abde-rtems/sparc-ab-rtems/lib/soft   -mtune=v8 -msoft-float -fcommon -DTARGET_ALDEBARAN   -o o-optimize/faster_rcnn.exe  o-optimize/init.o o-optimize/lrn_layer.o       
o-optimize/lrn_layer.o: In function `lrn_layer':
lrn_layer.c:(.text+0x4a8): undefined reference to `powf'
collect2: error: ld returned 1 exit status
make: *** [o-optimize/faster_rcnn.exe] Error 1

Solution

  • The compile process is composed of compilation of each individual .c files and final linking. I found somehow the -lm option which was added through XCFLAGS is being applied to the compilation command but not in the linking command. So I added -lm option in the object list so that that option is naturally following the object list in the link command. (I guess the proper way is to add -lm to the XLDFLAG because I found the variable in rtems build tree : extra LD flags). I'll try later..

    OBJS= $(COBJS) $(CXXOBJS) $(ASOBJS) -lm