Is there any way to compile a C program so that it can use all CPU cores in Linux.
No, not as magically as you want it to happen. Parallelization of programs is a very difficult subject and in general cannot be done automagically. BTW, parallel programs might not be as efficient as you wish them to be (be aware of Amdahl's law).
However, you could design and code a parallel program. You might for example use posix threads. Beware, it is tricky! Read first some Pthread tutorial. You won't be sure that all cores would be used (since they are managed by the kernel), but that is in practice very likely. Read also about processor affinity.
You could also use OpenMP or OpenACC. You could code some of your numerical kernels using OpenCL. You could have a multi-processing approach (e.g. forking several processes, using inter-process communications), perhaps using MPI. Look also into the MapReduce approach, the 0mq library (and many others).
You could read something on OSes, e.g. Operating Systems: Three Easy Pieces. You could also read something on Linux system programming, e.g. Advanced Linux Programming (or some newer book). See also intro(2) and syscalls(2) & pthreads(7).
Be aware that designing, coding and debugging a parallel (or concurrent, or distributed) application is very difficult. Take into account the cost of development time (and the time, probably years, needed to acquire the relevant skills). There is No Silver Bullet!
(it is not very realistic to transform an existing real-life sequential application into a parallel one; you usually have to design a parallel program from scratch)