Question: I was wondering why executables (written in c++) have to be recompiled from sources on every linux machine, even if the machines are software and hardware the same?

I had a search engine, written in c++, and I have to recompile it every time I want to move it on a new linux machine to make it work.

Any ideas?

Answer: 
The recompilation is ensuring you get optimal performance on your machine, because each time the configuration script is running to find dependencies and settings. This also ensures the openness of software as its source is always available and is modifiable by an appropriate agents - that is us.
This is not necessarily the case. Consider how Ubuntu packages are installed for example - <https://askubuntu.com/questions/162477/how-are-packages-actually-installed-via-apt-get-install> 

Apparently these are not compiled from source on the destination machine, but installed as pre-built binaries. Having said that, it is generally a good idea to build binaries from source on the machine that they will run on as you will avoid potential problems such having incompatible shared libraries (such as libc) which can occur when building something on Linux X and running on Linux Y.