What is the difference between g++ and gcc?

2018-12-31 06:11发布

What is the difference between g++ and gcc? Which ones should be used for general c++ development?

标签: c++ gcc g++
10条回答
孤独总比滥情好
2楼-- · 2018-12-31 07:06

For c++ you should use g++.

It's the same compiler (e.g. the GNU compiler collection). GCC or G++ just choose a different front-end with different default options.

In a nutshell: if you use g++ the frontend will tell the linker that you may want to link with the C++ standard libraries. The gcc frontend won't do that (also it could link with them if you pass the right command line options).

查看更多
千与千寻千般痛.
3楼-- · 2018-12-31 07:09

The only notable difference is that if you pass a .c to gcc it will compile as C, whereas g++ will always treat it as C++.

查看更多
墨雨无痕
4楼-- · 2018-12-31 07:10

Although the gcc and g++ commands do very similar things, g++ is designed to be the command you'd invoke to compile a C++ program; it's intended to automatically do the right thing.

Behind the scenes, they're really the same program. As I understand, both decide whether to compile a program as C or as C++ based on the filename extension. Both are capable of linking against the C++ standard library, but only g++ does this by default. So if you have a program written in C++ that doesn't happen to need to link against the standard library, gcc will happen to do the right thing; but then, so would g++. So there's really no reason not to use g++ for general C++ development.

查看更多
永恒的永恒
5楼-- · 2018-12-31 07:13

gcc and g ++ are both GNU compiler. They both compile c and c++. The difference is for *.c files gcc treats it as a c program, and g++ sees it as a c ++ program. *.cpp files are considered to be c ++ programs. c++ is a super set of c and the syntax is more strict, so be careful about the suffix.

查看更多
登录 后发表回答