The problem disappeared, when I have removed the "libpthread-dev" package from the machine, where g++ didn't work. Probably libpthread-dev should be marked as conflicting with the g++?