避免链接到 libstdc++ [英] Avoid linking to libstdc++
问题描述
我正在开发一个嵌入式项目,该项目目前在 Linux 和 uClibc 中使用 C.我们有兴趣将其移至 C++,但我不希望与 libstdc++ 中的链接相关的开销.我的印象是,如果我们不使用 STL 中的任何东西,例如 iostream 或 vector,这是可能的.
I'm working on an embedded project that currently uses C in Linux and uClibc. We're interested in moving it to C++, but I don't want the overhead associated with linking in libstdc++. My impression is that this is possible provided we don't use anything from STL, such as iostream or vector.
如何在不链接到 libstdc++ 的情况下指导 g++ 编译?
How does one direct g++ to compile without linking to libstdc++?
推荐答案
编译时,使用g++ -c
只编译.然后对于链接,使用 ld
而不是 g++
.这会直接调用链接器,但是这需要您在命令行上命名所有库(包括 libc 和 libcrt).
When you compile, use g++ -c
to compile only. Then for linking, use ld
instead of g++
. This invokes the linker directly, which requires you to name all your libraries on the command line (including libc and libcrt), however.
或者,如果您使用 g++ 作为更好的 c",您可以在最后的链接步骤中使用 gcc
(这将自动包含 libc)
Alternatively, if you're using g++ as a "better c", you may be able to use gcc
for your final link step (which will include libc automatically)
这篇关于避免链接到 libstdc++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!