4.8 Bdb headers were not found however 4.8 so is found and hence the build still uses 4.8 so and hence making it incompatible with 5.1 db wallet.
found below in ./configure output.
configure: WARNING: Found Berkeley DB other than 4.8; wallets opened by this build will not be portable! checking for main in -ldb_cxx-4.8... yes
I suppose the header files and so files should be of same version and in case its made for incompatible bdb then not to check for cxx.
took me 2 day to figure out the issue.