Skip to content

Instantly share code, notes, and snippets.

@seansawyer
Last active February 26, 2016 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seansawyer/74c0e016c30ad041b085 to your computer and use it in GitHub Desktop.
Save seansawyer/74c0e016c30ad041b085 to your computer and use it in GitHub Desktop.
Various Helpful C Tools

Print all libs loadable at runtime

ldconfig -p
# 208 libs found in cache `/etc/ld.so.cache'
#     libz.so.1 (libc6,x86-64) => /lib64/libz.so.1
#     libz.so (libc6,x86-64) => /usr/lib64/libz.so
# ...

Print all libs loadable at compile time

pkg-config --list-all
# gmodule-export-2.0    GModule - Dynamic module loader for GLib
# gmodule-2.0           GModule - Dynamic module loader for GLib
# ...

Print Postgres' include and library paths

/usr/pgsql-9.5/bin/pg_config --includedir --libdir
# /usr/pgsql-9.5/include
# /usr/pgsql-9.5/lib

Write include and linker flags for a library

pkg-config --cflags --libs libpq
# Package libpq was not found in the pkg-config search path.
# Perhaps you should add the directory containing `libpq.pc'
# to the PKG_CONFIG_PATH environment variable
# No package 'libpq' found

Augment pkg-config's path and try again

PKG_CONFIG_PATH=/usr/pgsql-9.5/lib/pkgconfig/ pkg-config --cflags --libs libpq
# -I/usr/pgsql-9.5/include  -L/usr/pgsql-9.5/lib -lpq

Check if the linker can find a library

ld -lpq
# ld: cannot find -lpq

Check if the linker can find a library in a particular place (the warning can be ignored since we have no main method)

ld -L/usr/pgsql-9.5/lib -lpq
# ld: warning: cannot find entry symbol _start; not setting start address

List all files in an installed package:

rpm -ql package-name

List the files in an RPM:

rpm -qlp package.rpm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment