gcc 库混乱

发布于 2024-10-10 01:21:09 字数 391 浏览 1 评论 0原文

这些天我花了一些时间研究 gcc 的内部结构。我找到了 gcc 提供的用于支持我们的程序的库集合。

libgcc(GCC 运行时库)有什么用。我的意思是该库最常用的函数是什么? :-/

我发现有一个库 libiberty 。我发现该库包含许多常用函数(我指的是我使用的例程),包括 allocaconcatcalloc 。但我找不到与它们类似的函数,例如 malloc 和其他字符串例程。所以当我们包含 < string.h >< alloc.h > 是不是头文件链接了两个不同的库?

我的概念还不够好。 :(请帮忙..

I hav been spending some time these days going through gcc internals. I found the collection of libraries that gcc provides for support to our programs.

What is the use of libgcc (The GCC runtime library.) I mean which are the most commonly used functions of that library?? :-/

And I found that there was a library libiberty . I found the library incorporates many of the commonly used functions(i mean the routines i use) including alloca , concat ,and calloc. But I couldnt find functions similar to theem like malloc and other string routines. So when we include < string.h > or < alloc.h > is it that the header file is linked with two different libraries??

My concepts arent good enogh. :( please help..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

小霸王臭丫头 2024-10-17 01:21:09

libgcc 包含可解决硬件“限制”的辅助函数;例如,64 位整数除法是 x86(_32) 上 libgcc 的一部分——臭名昭著的 __udivdi3

libgcc contains auxiliary functions that work around "limitations" of the hardware; for example, 64-bit integer divide is part of libgcc on x86(_32) — the infamous __udivdi3.

人事已非 2024-10-17 01:21:09

您可以将库视为可以在程序中使用的函数的实现,而无需为它们编写代码。例如:您使用“printf”函数,但实际上并未编写“printf”的代码。所以简单来说,库是常用​​代码(或函数)的实现的集合。

当您编译和链接程序时,根据链接选项,您的程序将与其他库链接(静态或动态)。

阅读有关静态和动态链接的更多详细信息并更好地理解库。

让我们举个例子:

#include <stdio.h>
#include <math.h>    // contains deceleration of sqrt function

int main ()
{
printf ("sqaure root of 4 is %d.", sqrt (4));
}

在这段代码中,我们使用了 sqrt 函数,但我们没有实现它。
现在,如果我们编译它并将其与包含 sqrt 函数定义的库(数学库)链接,我们的代码将在运行时正常工作。

但是,如果您不想链接到数学库,则必须编写自己的函数来计算 sqrt。

通过发出以下命令来编译和链接数学库:

gcc file.c -lm

这里,-l 用于提及我们将链接一个库
-lm 告诉链接“m”(或数学)库。

有关更多详细信息,请阅读链接器。

You can think library as the implementation of functions that you can use in your program without bothering to write code for them. For eg: you use 'printf' function, but you don't actually write the code for 'printf'. So in simple terms, libraries are the collection of implementation of commonly used code (or functions).

When you compile and link your program, based on the linking options, your program is linked (statically or dynamically) with other libraries.

Read about static and dynamic linking for more details and better understanding of libraries.

lets take an example:

#include <stdio.h>
#include <math.h>    // contains deceleration of sqrt function

int main ()
{
printf ("sqaure root of 4 is %d.", sqrt (4));
}

In this code, we are using the sqrt function, but we are not implementing it.
Now if we compile and link it with the library containing the definition of sqrt function (math library), our code will work fine at run time.

However, if you don't want to link to the math library, you will have to write your own function for computing sqrt.

compile and link math library by issuing:

gcc file.c -lm

here, -l is used for mentioning that we are going to link a library
-lm tells to link the 'm' (or math) library.

For more details, read about linkers.

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