无法在库内找到对 std 库数学函数的引用

发布于 2024-08-25 20:32:30 字数 1331 浏览 7 评论 0原文

我有几个使用共享库的程序。这些共享库依次使用各种标准 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

来世叙缘 2024-09-01 20:32:31

将 $(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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文