I think this isn't a problem with the g++ compiler, I think the compiler is telling you it found a problem while compiling, and if I remember correctly, the error code you posted:
/usr/lib/gcc/i586-poky-linux/4.8.2/../../../../i586-poky-linux/bin/ld: cannot find -lopencv_ts
collect2: error: ld returned 1 exit status
I think it means there's an OpenCV package missing, why don't you check AlexT's repo and install it?
Also, check this post, there's a user with the same error code, maybe it helps you.
Please tell us if this helps.