Convert from PEM to DER (via the X509_PEM_read_xxxx funtions) and use X509_cmp. PEM format is not guaranteed – you could have differnet linebreaks, for example.