If you're doing this strictly for learning the inner machinery of how a CNN works, then whipping up something in C++ or python or your language of choice is fine, and can be a good learning exercise. In order to train the weights, you'll want to define a loss function that takes the expected output (i.e. labels), and the predicted output, and do the back-propagation of the error signal through your network. There is a python tutorial that does this here: https://towardsdatascience.com/convolutional-neural-networks-from-the-ground-up-c67bb41454e1
If you want something with performance and stability, I'd strongly recommend starting with either Pytorch or Tensorflow, as they have built-in loss functions and autograd built in, and they are optimized for Gpu execution, so not running 4-5 for loops. Pytorch has a CNN tutorial here: https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html
and Tensorflow here: https://www.tensorflow.org/tutorials/images/cnn