Any difference with gcc vs. g ++?

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

I have a big C project, and I just switched part of the code to C ++. The code does not yet use the std C ++ library, so -llibstdc++ not required.

+8
c ++ c gcc linker
source share
3 answers

The main difference is that (assuming the files are detected as C ++) g ++ sets the flags necessary for linking to the standard C ++ library. It can also configure exception handling. I would not rely on the fact that just because your application does not use a standard library that is not needed when compiling C ++ (for example, the default exception handler).

EDIT: As stated in the comments, you will have problems with any constructors (which work) for static objects, as well as without getting virtual function tables (so if you use these functions in C ++, you still need to link this library) .

EDIT2: If you are not using the special C99 code in your C project, I would simply switch to compiling everything, like C ++, as a first step in your migration process.

+8
source share

gcc and g++ are only driver programs that do nothing but call other programs, so you can use the -v option to see exactly what they are doing, which other programs they call using what they say. That way, you can see exactly what the difference between the gcc and g++ bindings for a particular version and gcc architecture you might have installed. However, you cannot rely on the fact that you remain the same if you want to bear.

Depending on what you are doing, you may also be interested in the argument -###

0
source share

I think the g ++ linker will look for CPP function names, and it is different from C. I'm not sure if gcc can handle this. (If you can explicitly use version C, not C ++).

Edit:

It should work if you have

 extern "C" { <declarations of stuff that uses C linkage> } 

in your code, and the object file is compiled with g++ -c . But I will not argue about this.

-2
source share

All Articles