English 中文(简体)
为什么不给依赖者悬挂国旗就建立这种共同的平衡呢?
原标题:Why is it okay to create this shared lib without -l flags for dependencies?

有关连接的规则正被 j笑。

我有这份少许的文件,我想变成一个共享的图书馆。 为说明起见,Im打上libuv功能,但它同样也可以从任何图书馆打电话。

// func.c
#include <uv.h>

int func(void) {
  uv_close(NULL, NULL);

  return 0;
}

我将其汇编成一个共享的图书馆;我注意到我与<条码>libuv<>/代码>没有联系。 提供<代码>-luv 国旗至cc:

$ cc -fpic -g -c func.c
$ cc -shared -o libfunc.so func.o
$ ldd ./libfunc.so
        statically linked
$

我不理解“法定联系”产出实际上意味着什么——我认为我这样通过具体说明<条码>共享<<><>/条码>,创造了一种共同的平衡(而不是静态的平衡)。

不管怎样,为了让大家感觉到事情,我接下来试图创造我共同的平衡,明确连接<条码>libuv<>:>:

$ cc -fpic -g -c func.c
$ cc -shared -o libfunc.so func.o -luv
$ ldd ./libfunc.so
        linux-vdso.so.1 (0x00007ffe2b39a000)
        libuv.so.1 => /lib/x86_64-linux-gnu/libuv.so.1 (0x00007f012d6d0000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f012d4a7000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f012d710000)
$

www.un.org/Depts/DGACM/index_spanish.htm 请解释在创建<条码>libfunc.<>>>的两种不同“方法”之间发生的情况。 共享图书馆: 为什么在<条码>上添加<代码>-luv,<>条/代码>的旗帜导致通过<条码>ldd创建/确认这些附属地? 另外,第一种版本(没有<代码>-luv)为什么甚至可行? 我认为,我正在利用另一个图书馆的功能obliged me,在连接期间提供正确的-l论点,也就是说,我认为,试图创建共享的图书馆而没有<>>>/m>具体规定-luv是失败的。


最新消息:继对JohnBollinger的评论之后,我重复了“条码”-fpic 链接指令的旗帜,但似乎没有影响观察到的行为:

$ cc -fpic -g -c func.c
$ cc -fpic -shared -o libfunc.so func.o
$ ldd ./libfunc.so
        statically linked
$
$ cc -fpic -g -c func.c
$ cc -fpic -shared -o libfunc.so func.o -luv
$ ldd ./libfunc.so
        linux-vdso.so.1 (0x00007fff043f0000)
        libuv.so.1 => /lib/x86_64-linux-gnu/libuv.so.1 (0x00007fea17963000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fea1773a000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fea179a3000)
$

更新:我的<代码>gcc/code>/> cc<>/code>和ld版本:

$ gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 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.

$ cc --version
cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 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.

$ ld --version
GNU ld (GNU Binutils for Ubuntu) 2.38
Copyright (C) 2022 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
$

Mylav distro, fwiw, 即乌班图·WSL, 释放jammy:

$ uname -a
Linux US193F98B0DB51 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
$

I assumed:我主持世界语言学会的工作是毫不相干的,但“JohnBollinger”不能照搬我对RHEL/Centos 8的结果,我对一切都不清楚。 我无法使用物理的六氯环己烷箱来比较那里的行为。


在“DarkSoda”查询后,似乎两种版本的<代码>libfunc.so。 (在连接期间,与<代码>-luv和>无)相同:

$ cc -fpic -g -c func.c
$ cc -fpic -shared -o libfunc.so func.o
$ ls -l ./libfunc.so
-rwxr-xr-x 1 user user 20528 Jan 11 18:53 ./libfunc.so
$
$
$ rm -f ./func.o ./libfunc.so
$
$ cc -fpic -g -c func.c
$ cc -fpic -shared -o libfunc.so func.o -luv
$ ls -l ./libfunc.so
-rwxr-xr-x 1 user user 20528 Jan 11 18:53 ./libfunc.so
$
问题回答

我很奇怪,两种生成的校准体的大小是否不同。 看来,第一种版本(无——卢夫)有些是静态地与平衡联系在一起的。 如此(因为没有使用静态)





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...