Hi , I have a mix-up of C and C++ files . I initially developed in Codewarrior environment for Coldfire. Now, I am migrating to Cygwin environment for development. I find that in Codewarrior there is one compiler option 'Force C++ compilation' that makes all the C files also to act like C++ files . (something like that .) So, it is possible to mix-up code / routine-calls between C and C++ in codewarrior and the development was easy. I would like to know an equivalent 'Force C++ compilation' option in Cygwin (M68K cross-Tool). I believe that there must be a simple small flag that will do that in Cygwin environment M68K cross- tool package so that it would ease the development activity. Currently, i am doing some manual coding of the following to mix-up usage of the C and C++ code-files and i believe that there is surely another simple way in cygwin (M68K cross-tool package). #ifdef __cplusplus extern "C" { #endif it's usually partnered at the other end of the file by #ifdef __cplusplus } #endif Is there any quivalent simple flag option in cygwin ? Thx in advans, Karthik Balaguru
Codewarrior "Force C++ compilation" equivalent in cygwin - M68K cross-tool package
Started by ●October 12, 2006
Reply by ●October 16, 20062006-10-16
KBG wrote:> Hi , > > I have a mix-up of C and C++ files . I initially developed in > Codewarrior environment for Coldfire. > Now, I am migrating to Cygwin environment for development. I find that > in Codewarrior there is one > compiler option 'Force C++ compilation' that makes all the C files also > to act like C++ files . > (something like that .) So, it is possible to mix-up code / > routine-calls between C and C++ in > codewarrior and the development was easy. > > I would like to know an equivalent 'Force C++ compilation' option in > Cygwin (M68K cross-Tool). > I believe that there must be a simple small flag that will do that in > Cygwin environment M68K cross- > tool package so that it would ease the development activity. > > Currently, i am doing some manual coding of the following to mix-up > usage of the C and C++ code-files and i believe that there is surely > another simple way in cygwin (M68K cross-tool package). > > #ifdef __cplusplus > extern "C" { > #endif > > it's usually partnered at the other end of the file by > > #ifdef __cplusplus > } > #endif > > Is there any quivalent simple flag option in cygwin ? > > Thx in advans, > Karthik Balaguru >First off, you've got your compiler and environment names thoroughly mixed up, so I'm guess that you are referring to a gcc cross-compiler running under cygwin. If you are trying to force all your .c files to be compiled using the c++ compiler, you can use the switch "-x c++" to force the compilation language, as noted in the gcc manual: http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Overall-Options.html#Overall-Options Of course, that's the wrong way to handle C/C++ mixtures, just as the "Force C++ compilation" Code Worrier flag is the wrong way to do it. The best method is to use the #ifdef __cplusplus sequences you mentioned to wrap all your "extern" declarations in the header files. There is no need for these wrappers in the C files themselves, assuming each module #include's its own header file and objects are either declared "extern" in the header file, or "static" in the module file. Thus you compile your C files as C files, and use the #ifdef's to get the linkage right.