与 gcc 与 g++ 链接有什么区别? [英] Any difference in linking with gcc vs. g++?

查看:21
本文介绍了与 gcc 与 g++ 链接有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gcc和g++的链接过程有什么不同吗?

Are there any differences in the linking process between gcc and g++?

我有一个大型 C 项目,我刚刚将部分代码切换到 C++.该代码尚未使用标准 C++ 库,因此暂时不需要 -llibstdc++.

I have a big C project and I just switched part of the code to C++. The code isn't using std C++ library yet, so -llibstdc++ isn't needed for now.

推荐答案

主要区别在于(假设文件被检测为 C++)g++ 设置了与 C++ 标准库链接所需的标志.它还可以设置异常处理.我不会相信仅仅因为您的应用程序不使用标准库而编译为 C++ 时不需要它(例如默认异常处理程序).

The main difference is that (assuming the files are detected as C++) g++ sets up the flags needed for linking with the C++ standard library. It may also set up exception handling. I wouldn't rely on the fact that just because your application doesn't use the standard library that it isn't needed when compiled as C++ (for example the default exception handler).

正如评论中所指出的,对于静态对象以及没有获取虚函数表的任何构造函数(确实有效)都会遇到问题(因此,如果您使用 C++ 的这些功能,您仍然需要链接那个图书馆).

As pointed out in comments you'll have trouble with any constructors (that do work) for static objects as well as not getting virtual function tables (so if you're using those features of C++ you still need to link that library).

除非您在 C 项目中使用 C99 特定代码,否则我实际上只是切换到将整个代码编译为 C++ 作为迁移过程的第一步.

Unless you're using C99 specific code in your C project I would actually just switch to compiling the whole thing as C++ as the first step in your migration process.

这篇关于与 gcc 与 g++ 链接有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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