You can build a generalized suffix tree for a set of strings with multiple strings using this implementation. A suffix tree contains all the suffixes of the given text as their keys and positions in the text as their values.
string longestCommonSubstring(const string& str1, const string& str2) { if(str1.empty() || str2.empty()) { return 0; } int *curr = new int [str2.size()]; int *prev = new int [str2.size()]; int *swap = NULL; int maxSubstr = 0; string longest; for(unsigned int i = 0; i