'undefined reference' errors when compiling against library 'undefined reference' errors when compiling against library unix unix

'undefined reference' errors when compiling against library


Those are Linking errors, which tell you the linker cannot find definitions for the library you are using.
You will have to link the library to your project.

gcc <your files for compilation> -lLibName

Read this for better understanding.


I still get the error even if

  1. readline library is installed and
  2. -lreadline is added to gcc compiling command.

The root cause of my issue is the order of the libraries/code: -lreadline (and other libraries) should be put right before -o options.