C ++标准库如何链接到我的应用程序? [英] How is the C++ standard library linked to my application?

查看:91
本文介绍了C ++标准库如何链接到我的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我通常使用来自第三方(非标准)C ++库的代码(包括标头)时,预构建的二进制文件会链接到(或包含在)代表我的应用程序的目标可执行文件中,但是C ++会发生什么情况标准库?据我所知,我不必附带仅使用C ++标准库中代码的应用程序附带的库,因此代码是否静态链接并包含在可执行文件中?

When I usually use code (include headers) from 3rd party (non-standard) C++ libraries, a pre-built binary file is linked to (or included in) the target executable that represents my application, but what happens with C++ standard library?, as far as I have seen I don't have to ship a library with an application that uses code only from the C++ standard library, thus is the code statically linked and included in the executable?

推荐答案

不,默认情况下,标准库在运行时动态链接.

No, the standard libraries by default are dynamically linked at runtime.

运行动态加载程序时,如果发现动态加载程序可以加载并运行,它将在几个标准位置查找动态库,否则应用程序将退出.

When running the dynamic loader will look in a couple of standard places for dynamic libraries if it finds it loads and runs otherwise the application quits.

在Unix系统上:
/usr/lib:查找:libstdc ++ *

On Unix Systems:
/usr/lib: look for: libstdc++*

在Windows上:
c:\ windows \ system32寻找:MSVCRT.DLL

On Windows:
c:\windows\system32 look for: MSVCRT.DLL

还有一些环境变量可能会影响搜索路径.在dlopen的平台手册页上查看它们的含义.您需要的所有内容都应该在平台上的dlopen的手册页中.

There are also a couple of Environment variables that can affect the search path. Look at your platforms man page for dlopen to see what they are. Everything you need should be in the man pages for dlopen on your platform.

大多数系统在适当的位置具有这些库,并且会自动找到它们.
STL的其余部分将不会引入额外的共享库依赖性.

Most systems have these libs in the appropriate places and will automatically be found.
The rest of the STL will not introduces extra shared lib dependencies.

这篇关于C ++标准库如何链接到我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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