add cpp code of BuildNetworks.m