相关疑难解决方法(0)

如何为共享库设置动态链接器路径?

我想用一个.interp段编译一个共享库。

#include <stdio.h>

int foo(int argc, char** argv) {

    printf("Hello, world!\n");
    return 0;

}
Run Code Online (Sandbox Code Playgroud)

我正在使用以下命令。

gcc -c -o test.o test.c
ld --dynamic-linker=blah -shared -o test.so test.o
Run Code Online (Sandbox Code Playgroud)

我最终没有INTERP段,就好像我从未通过过该--dynamic-linker=blah选项一样。用检查readelf -l test.so。生成可执行文件时,链接器会正确处理该选项,并将INTERP段放在程序头中。如何使它也适用于共享库?

linker gcc shared-libraries elf ld

5
推荐指数
1
解决办法
9253
查看次数

使用main()创建共享库

glibc(以及我相信的EGLIBC)中,libc.so库有一个main()方法:

$ /lib/i386-linux-gnu/libc.so.6
GNU C Library (Debian GLIBC 2.19-18+deb8u1) stable release version 2.19, by Roland McGrath et al.
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.8.4.
Compiled on a Linux 3.16.7 system on 2015-08-30.
Available extensions:
        crypt add-on version 2.1 by Michael Glad …
Run Code Online (Sandbox Code Playgroud)

c linux linker shared-libraries

3
推荐指数
1
解决办法
1286
查看次数

标签 统计

linker ×2

shared-libraries ×2

c ×1

elf ×1

gcc ×1

ld ×1

linux ×1