add cpp extern guard

I find this snip useful for myself, hope it can also be useful for others. Thanks!