它将链接到哪个库-静态或共享对象 [英] What library would it link against - static or shared object

查看:102
本文介绍了它将链接到哪个库-静态或共享对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于C ++的项目(许多源文件),通过一个makefile使用gnu make进行编译. 我有一个链接库的应用程序,例如mylib.现在,mylib由其他一些开发人员拥有.我看到在生成库二进制文件的路径中存在2个文件,即 libmylib.so(共享库)和libmylib.a(静态库存档文件)

I have a C++ based project(many source files) compiled using gnu make via a makefile. I have an application which links a library, say mylib. Now mylib is owned by some other developer. I see 2 files present in the path where the library binaries are generated namely libmylib.so (shared object) and libmylib.a (static library archive file)

我的应用程序makefile具有以下链接器选项,用于链接库mylib

My application makefile has below linker option to link the library mylib

LDFLAGS + =-l:mylib ...

LDFLAGS+=-l:mylib ...

问题是mylib将在应用程序可执行文件中链接哪个版本的库

Question is what version of the library mylib would be linked in my application executable

共享对象libmylib.so还是静态版本libmylib.a?

Would the shared object libmylib.so or static version libmylib.a ?

如何确定,是否还有其他makefile选项来管理此问题?

How would it be decided, would there be any other makefile option to govern this?

推荐答案

默认情况下,在非嵌入式Linux上,您将获得动态链接.如果要更改它,可以在LDFLAGS;

By default on non embedded Linux, you'll get dynamic linkage. If you want to change that, you can specify it in LDFLAGS;

LDFLAGS+= -Wl,--Bstatic -lmylib -Wl,--Bdynamic

(可能需要用引号引起来),仅此lib会切换为静态,然后恢复为默认动态.

(possibly quotes are required) This will switch to static for this lib only, then back to the default dynamic.

这篇关于它将链接到哪个库-静态或共享对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆