Any difference in linking with gcc vs. g++?(与 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++ 链接有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:与 gcc 与 g++ 链接有什么区别?
基础教程推荐
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01