Strange issue in gcc windows

Last week I came across a strange situation in gcc for windows. I have written some c++ codes in linux where some of the function bodies i kept in header files only.

like this

class temp

{

string m;

public:

void setm(string param){ m = param;}

string getm(){ return m;}

}

 

This is working fine when compiled and used in linux. But when I use same gcc version in windos 64 , it compiles but crashes at run time as it couldn’t locate function bodies. Will look into this farther .

Reducing size of executable in mingw/gcc

I was compiling some basic codes in qt. I observed that even for a hello world project , it is taking close to 1 mb , even in release mode. So did a google search on that. Found that main culprits are

  • Included debuging info.
  • included standard libraries.
  • RTTI , EXCEPTION handling, usage of templates.

In my case, usage of templates is the main reason. Seems like compiler loves to generate different codes for each template instances. Eg. vector<int> and vector<string> will have different implementation.

Solution is to disable the above mentioned features using some compiler options

-fno-rtti
-fno-exceptions

For complete list of options check this. You may also consider packing your executable using UPX.

Conio.h for g++

Lets admit it , most of our colleges don’t care about c++ standards while teaching c++. That is why borland c++ (or turbo c++) is still used in many college labs. But problem is , since they are not compatible with any c++ standards , people face difficulties once they are out of college. One of my colleague has a large personal c++ code base , which was entirely written in his college days using that outdated non standardised compiler. So functions like getch(),clrscr(),cprintf() etc are used widely. Now he was unable to compile any code in his linux box , and the reason was conio.h . I just googled and found that he was not alone. And there is actually a conio.h available for g++ too 🙂

 

You may visit here to have a look at it , in-case you require that

http://linux-conioh.sourceforge.net/