On 20/03/14 13:10, Eric Wolf wrote: > On 3/20/2014 7:29 AM, Tim Prince wrote: >> On 3/20/2014 4:27 AM, Eric Wolf wrote: >>> >>> We have a big bunch of C and C++ code in our product and compile >>> main with g++, because I read in >>> >>> http://www.parashift.com/c++-faq/overview-mixing-langs.html >>> >>> that this is needed. >> >> The proper compile mode will be selected regardless of whether you >> invoke gcc, g++, gfortran, ... e.g. according to the file name. As >> your reference pointed out, that is not true of many other compilers. > > That's not the point. > > I can easily move the main function into a file ending with .c. Linking > will still succeed, but I assume, that things will start to go terribly > wrong, when the c++ code throws an exception, which is caught nowhere, > or if one tries to use a global non pod object. Why do you /assume/ this? Just try it and see. It should be a simple matter to write a few test files. > > Here I need a catalog of things, I am not allowed to do in the c++ > portion of the code, so that nothing goes wrong. > >> The second point in that reference is valid: g++ includes -lstdc++ >> implicitly, which the other languages do not, so that g++ references >> can be satisfied during linking. > > That's useful. So I can use ld to link again, as long as I include > -lstdc++ Option. That's all? It is normal practice to use gcc (or g++) to run the linker, rather than calling it explicitly. It makes it easier to get the write options passed on, and makes everything a little more consistent. > > Please excuse the missing References header. I subscribed the digest > version of the mailing list and my mail programm is defective. I can't > set the References header by hand. > > Yours sincerely, > > Eric Wolf > > Have you tried googling for "difference between gcc and g++"? There are plenty of good answers here. <http://stackoverflow.com/questions/172587/what-is-the-difference-between-g-and-gcc> The key points are that "-lstdc++" is included by g++ when you use it for the linker - you need to add it explicitly if using gcc to link. And it seems that g++ will treat .c files as C++, while gcc treats them as C files. So the key issue is not whether you will use g++ or gcc, but whether you can compile main() in a language other than C++ and still get features such as static constructors and full exception handling. I don't know the answer to that one.