install C/C++ compilers:

sudo apt-get update
sudo apt-get install build-essential

install mysql library for C/C++:
sudo apt-get install libmysqlclient-dev

compile a C program:

gcc -o app-name source-file-name.c
it will generate a file called app-name in your current location.
source-file-name.c – is the path/name of your source file of the program
instead of app-name you can specify the entire path of the location where the final app file should be generated: gcc -o /var/my_apps/bin/app-name /var/my_apps/src/mysource-file-name.c

compile a C program using the MySQL client library:
gcc -o app-name $(mysql_config --cflags) source-file-name.c $(mysql_config --libs)
more details about mysql_config parameters here: https://dev.mysql.com/doc/refman/5.7/en/c-api-building-clients.html

if you want to compile a C++ program, just use g++ instead of gcc:
g++ -o app-name source-file-name.cpp

 

C program examplehello-world.c file:

/* 
Hello World program printing a 'Hello World!' message
*/
#include <stdio.h>

int main() {
 printf("Hello World!\n");
               
 return 0;
}

compile it:
gcc hello-world.c -o hello-world
run it:
./hello-world
result:
hello-world.c