Linux 如何在makefile中包含*.so文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10689040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to include *.so file in makefile
提问by MetallicPriest
For a program I was linking the static glibc library (which I modified). My makefile looks something like this.
对于一个程序,我正在链接静态 glibc 库(我修改过)。我的 makefile 看起来像这样。
CXX = g++
CXXFILES = main.c
CXXFLAGS = -g -o prog -D_GNU_SOURCE
LIBS = ../../nptl/libpthread.a ../../libc.a -lpthread
all:
$(CXX) $(CXXFILES) $(LIBS) $(CXXFLAGS)
However, instead of using the static *.a files, I now want to use the dynamic shared object *.so files. Is it enough to replace the *.a files by *.so files in the makefile. If not what is the correct way of doing so. I tried to simply replace the *.a with *.so files in the makefile, but it seems like when I do that the program uses the original glibc (rather than my modified one).
但是,我现在想使用动态共享对象 *.so 文件,而不是使用静态 *.a 文件。将 *.a 文件替换为 makefile 中的 *.so 文件就足够了。如果不是这样做的正确方法是什么。我试图简单地将 *.a 替换为 makefile 中的 *.so 文件,但是当我这样做时,程序似乎使用原始 glibc(而不是我修改的 glibc)。
采纳答案by greg
If you don't want to use the standard libraries, you might need the -nostdlib
flag. In addition, if you want to dynamically link libraries, you need to tell the linker where they are. -L/dir/containing -lc
.
如果您不想使用标准库,则可能需要该-nostdlib
标志。另外,如果你想动态链接库,你需要告诉链接器它们在哪里。 -L/dir/containing -lc
.
If you don't want to set a LD_LIBRARY_PATH
when executing, you'll need to set rpath
, -Wl,--rpath=/path/containing
.
如果您不想LD_LIBRARY_PATH
在执行时设置 a ,则需要设置rpath
, -Wl,--rpath=/path/containing
。