In my sample C code, I use the mysqlclient to connect to a MySQL Server. Here is the Makefile.
example: example.c
$(CC) $< -o $@ `mysql_config --cflags --libs`
It works fine. But the produced example is dynamically linked, which is not what I want. What I want do is to link against libmysqlclient statically, while linking against other libraries dynamically, such as libz, libcrypto.
FYI. mysql_config's output with --cflags --libs:
$ mysql_config --cflags --libs
-I/usr/include/mysql -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions \
-fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE \
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv
-rdynamic -L/usr/lib64/mysql -lmysqlclient -lz -lcrypt -lnsl -lm \
-L/usr/lib64 -lssl -lcrypto