无法在库内找到对 std 库数学函数的引用
我有几个使用共享库的程序。这些共享库依次使用各种标准 C 库。即
程序 A 和程序 B 都使用共享库 S。共享库 S 使用 std C 数学。我希望能够将共享库 S 静态链接到标准库,然后将程序 A 和 B 静态链接到 S,这样我就不必拖动库文件,因为这些程序将在运行 BusyBox 0.61 的嵌入式系统。但是,当我尝试将程序静态链接到共享库 S 时,我收到来自 GCC 的错误消息:
../lib/libgainscalecalc.a(gainscalecalc.): In function 'float2gs':
[path to my C file].c:73: undefined reference to 'log'
有人可以帮我吗?我正在使用的 make 命令如下:
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_static.o
$(RANLIB) libgainscalecalc.a
chmod 777 libgainscalecalc.a
dynamiclib: gainscalecalc_dynamic.o
$(CC) -shared -o libgainscalecalc.so gainscalecalc_dynamic.o
chmod 777 libgainscalecalc.so
编辑: 链接共享库编译得很好,我只是还没有测试它们
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 lt; -I. $(INCFLAGS) -o $@
gainscalecalc_dynamic.o: gainscalecalc.c
$(CC) $(CFLAGS) -fPIC -c lt; -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_static.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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 $(LIBFLAGS) 放在 lgainscalecalc 之后。
链接器命令行与位置相关。将 -lm 放在库后面将导致链接器使用 libm.a 来解析库使用的引用。
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.