开发者

Unable to find reference to std library math function inside library

I've got several programs that use shared libraries. Those shared libraries in turn use various standard C libraries. ie

Program A and Program B both use Shared Library S. Shared Library S uses std C math. I want to be able to statically link Shared Library S against the standard library, and then statically link Programs A and B against S so that I don't have to be dragging around the library files, because these programs are going to be running on an embedded system running BusyBox 0.61. However, when I try to statically link the programs against Shared Library S, I get an error message from GCC stating :

../lib/libgainscalecalc.a(gainscalecalc.): In function 'float2gs':
[path to my C file].c:73: undefined reference to 'log'

Can somebody please help me out ? The make commands I'm using are below :

CFLAGS += -Wall -g -W
INCFLAGS = -I$(CROSS_INCLUDE)/usr/include  
LIBFLAGS += -L$(CROSS_LIB)/usr/lib -lm

gainscalecalc_static.o: gainscalecalc.c
$(CC) $(CFLAGS) -c $< -I. $(INCFLAGS) -o $@

gainscalecalc_dynamic.o: gainscalecalc.c
$(CC) $(CFLAGS) -fPIC -c $< -o $@

all: staticlib dynamiclib static_driver dynamic_driver

clean:
$(RM) *.o *.a *.so *~ driver core $(OBJDIR)

static_driver: driver.c staticlib
$(CC) $(CFLAGS) -static driver.c $(INCFLAGS) $(LIBFLAGS) -I. -L. -lgainscalecalc -o $@

dynamic_driver: driver.c dynamiclib
$(CC) $(CFLAGS) driver.c -o $@ -L. -lgainscalecalc

staticlib: gainscalecalc_static.o
$(AR) $(ARFLAGS) libgainscalecalc.a gainscalecalc_stati开发者_如何学Goc.o
$(RANLIB) libgainscalecalc.a
chmod 777 libgainscalecalc.a

dynamiclib: gainscalecalc_dynamic.o
$(CC) -shared -o libgainscalecalc.so gainscalecalc_dynamic.o
chmod 777 libgainscalecalc.so

Edit: Linking against the shared libraries compiles fine, I just haven't tested them out yet


Put the $(LIBFLAGS) after lgainscalecalc. The linker command line is position dependent. Placing the -lm after your library will cause the linker to use libm.a to resolve references your library uses.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜