Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any difference in linking with gcc vs. g++?

Tags:

c++

c

gcc

linker

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

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.

like image 583
Šimon Tóth Avatar asked Jul 18 '11 15:07

Šimon Tóth


People also ask

Is GCC and G ++ same?

DIFFERENCE BETWEEN g++ & gccg++ is used to compile C++ program. gcc is used to compile C program.

Can GCC perform linking?

Linking is performed when the input file are object files " .o " (instead of source file " . cpp " or " . c "). GCC uses a separate linker program (called ld.exe ) to perform the linking.

Does GCC use G ++?

g++ is a program that calls GCC and automatically specifies linking against the C++ library. It treats . c, . h and .

What does linking mean in GCC?

Linking is the process of collecting and combining various pieces of code and data into a single file that can be loaded (copied) into memory and executed. Linking is performed automatically by programs called linkers, which enable separate compilation.

Is G ++ faster than GCC?

It won't have a significant impact on load time, but it isn't identical. According to the documentation, GNU GCC and GNU G++ are one and the same.

What does the G in GCC stand for?

GCC stands for “GNU Compiler Collection”. GCC is an integrated distribution of compilers for several major programming languages. These languages currently include C, C++, Objective-C, Java, Fortran, and Ada.


1 Answers

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).

EDIT: 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).

EDIT2: 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.

like image 155
Mark B Avatar answered Oct 06 '22 03:10

Mark B