我正在尝试在rtems应用程序中使用powf函数。
当我打电话给powf(a,b);在Init()函数中,它可以编译。
但是,当我在其他函数中调用powf时,即使我有这些#include <math.h>
和#include <float.h>
,编译器也会为我提供“对powf的未定义引用”消息。我事件尝试合并文件,但它是相同的。
#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..
}
可能是什么问题?
EDIT(ADD):我在下面添加了源代码和makefile。编译的rtems OS软件包由外壳环境变量RTEMS_MAKEFILE_PATH指定。
生成文件:
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
make
命令的结果: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
最佳答案
编译过程由每个单独的.c文件的编译和最终链接组成。我发现以某种方式将通过XCFLAGS添加的-lm
选项应用于编译命令,而不应用于链接命令。因此,我在对象列表中添加了-lm
选项,以便该选项自然位于链接命令中的对象列表之后。 (我猜正确的方法是将-lm
添加到XLDFLAG,因为我在rtems build tree中发现了变量:多余的LD标志)。我稍后再试。
OBJS = $(COBJS)$(CXXOBJS)$(ASOBJS)-lm