避免链接到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屋!