我正在尝试在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..
}
可能是什么问题?
编辑(ADD):我在下面添加了源代码和makefile。编译的rtems OS包由shell环境变量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 /裸-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
答案 0 :(得分:0)
编译过程由每个.c文件和最终链接的编译组成。我发现通过XCFLAGS添加的-lm
选项正在应用于编译命令,但不会应用于链接命令。所以我在对象列表中添加了-lm
选项,以便该选项自然地跟随link命令中的对象列表。 (我想正确的方法是将-lm
添加到XLDFLAG,因为我在rtems构建树中找到了变量:额外的LD标志。我稍后会试试..
OBJS = $(COBJS)$(CXXOBJS)$(ASOBJS)-lm