Unresolved Reference in Ubuntu Linux

Mar 9, 2014 at 6:44 PM
Edited Mar 9, 2014 at 10:12 PM
I'm stuck on a seemingly simple issue. I can't figure out why this simple program has an undefined reference. I'm using Linux Ubuntu Server 12.04 with g++ 4.8 . Am I missing a header, library, compiler or linker option or what?

The error message is:
pgm.cpp:(.text+0x127: undefined reference to `web::http::uri::uri(char const*)'
... similar errors ...
Here's the entire program:
#include <cpprest/http_listener.h>
int main()
  web::http::experimental::listener::http_listener listener(U("http://localhost:3901"));
  return 0;
The command line to compile:
g++ -std=c++11 -I/home/bsalita/casablanca/Release/include/ -L/home/bsalita/casablanca/Binaries/Release64/ -L /usr/lib -lcasablanca -lcommon_utilities -lboost_system -lboost_thread -lboost_locale -lboost_regex pgm.cpp
Mar 10, 2014 at 6:17 PM
Hi BSalita,

Straightforward fix: Put pgm.cpp before all the link flags.

Explanation: When you use g++ in the "compile and link" mode, it changes all the .cpp files into .o files and then passes all the link flags and the .o files to the linker in the order they appear. This means you get a link command like "ld -lcasablanca -lcommon_utilities -lboost pgm.o". The linker then discards all the shared libraries because it doesn't see any reason to use them, then tries to link your .o file and fails to find symbols. This is fixed by announcing you need the symbols first (by putting the .o file requiring symbols first), then linking the libraries afterwards.

Another few minor things: You don't need to link against common_utilities; that's just for our tests. You probably should link against ssl though.

Good Luck!
Marked as answer by roschuma on 3/11/2014 at 1:32 PM
Mar 11, 2014 at 1:54 AM
The answer was nowhere on my radar. Thanks for your help. I was really lost. Thanks for the additional tips too.