2013년 5월 8일 수요일

gcc g++ 차이

인터넷을 겁나 뒤졌는데 -lstdc++ 과는 달리 차이가 좀 있는 것 같다.


http://stackoverflow.com/questions/172587/what-is-the-difference-between-g-and-gcc

가장 마음에 드는 답변.

로그 찍어보고 탐구하기엔 시간이 부족해.

gcc -std=c++0x -lstdc++  로 컴파일 하면 간지나 보였는데
걍 g++로 가는게 맞는 것 같다.

GCC: GNU Compiler Collection
  • Referrers to all the different languages that are supported by the GNU compiler.
gcc: GNU C Compiler
g++: GNU C++ Compiler
The main differences:
  1. gcc will compile: *.c/*.cpp files as C and C++ respectively.
  2. g++ will compile: *.c/*.cpp files but they will all be treated as C++ files.
  3. Also if you use g++ to link the object files it automatically links in the std C++ libraries (gcc does not do this).
  4. gcc compiling C files has less predefined macros.
  5. gcc compiling *.cpp and g++ compiling *.c/*.cpp files has a few extra macros.
Extra Macros when compiling *.cpp files:
#define __GXX_WEAK__ 1
#define __cplusplus 1
#define __DEPRECATED 1
#define __GNUG__ 4
#define __EXCEPTIONS 1
#define __private_extern__ extern
share|improve this answer
6
You can link the std C++ library in gcc by passing -lstdc++ parameter.Denilson Sá Aug 23 '10 at 0:13
There are more differences between 'gcc' and 'g++' than only the standard libraries, so gcc -lstdc++ will still not get you the same behavior as g++. We put all of that language-specific behavior into its own driver for a reason, that's what it's there for. :-)Ti Strga Jan 28 at 21:03
@TiStrga: You did not read the answer very carefully. Denilson is basically correct as he is only taking about the linking phase.Loki Astari Jan 28 at 22:54
My comment isn't talking about just linking... that's the point. Even just restricting the discussion to linking (which your answer was not), a user still won't be able to use the entire C++ standard library by only specifying -lstdc++, as there will be missing dependencies on math, RTTI, and exception information. Whether a given test case links or fails will depend on the operating system and which C++ features are used by the test case, which again is why all of that knowledge is built into the g++ driver instead of being left up to the user to figure out.Ti Strga Jan 29 at 15:38
Trust me, we have this discussion a lot, usually when a Linux user tries to move his incomplete Makefile to another platform. :-) The g++ link stage does a lot more than gcc -lstdc++ on other OSes, especially when the target is an embedded platform. Fortunately, that's why we ship a g++ in the first place.Ti Strga Jan 29 at 15:40
@TiStrga: Have to disagree on two counts: 1) You seem unable to read the answer in context. Which has nothing to do with linking but the differences between the gcc and g++ frontends. 2) Your assertations about gcc and g++ are also wrong. They are simple wrappers and you can actually tell the difference by dumping out there "spec" strings. g++ -dumpspecs. This shows exactly what they use to link with and options set to the backend.Loki Astari Jan 29 at 16:38
The spec strings are constructed to be specific to the compiler, which in turn are specific to the operating system and target. So if you run -dumpspec on (for example) a cross compiler targeting an embedded system, you will see the differences. There are more than just linker differences... which again, is what your answer was about (preprocessor macros, include paths, multiple runtime libraries). We seem to be talking past each other, but as a former GCC maintainer, I assure you I am familiar with what the frontends are and are not.Ti Strga Jan 29 at 17:02

댓글 없음:

댓글 쓰기

국정원의 댓글 공작을 지탄합니다.

UPBIT is a South Korean company, and people died of suicide cause of coin investment.

 UPBIT is a South Korean company, and people died of suicide cause of coin. The company helps the people who control the market price manipu...