12

I would like to use the Library cpp-netlib for a C++ project. Therefore I installed the boost library with the help of homebrew (OS is Mac OS X 10.8). Then I downloaded cpp-netlib from the projects homepage, used cmake to create the Makefile for g++ and successfully applied make. "make test" passed all its tests. Then I copied the include folder of cpp-netlib into the boost directory.

So here is when the trouble began: I tried to compile the documentation's first example http-client but couldn't get it to work. When I used

g++ test.cpp -o out -I/usr/local/Cellar/boost/1.53.0/include 
-L/usr/local/Cellar/boost/1.53.0/lib 
-lboost_system-mt -lboost_filesystem-mt -lboost_thread-mt

I received these linker errors:

Undefined symbols for architecture x86_64:
  "boost::network::uri::detail::parse(__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::network::uri::detail::uri_parts<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)", referenced from:
      boost::network::uri::uri::parse()  in ccs87Dq3.o
  "boost::network::http::impl::normal_delegate::normal_delegate(boost::asio::io_service&)", referenced from:
      boost::network::http::impl::connection_delegate_factory<boost::network::http::tags::http_async_8bit_udp_resolve>::new_connection_delegate(boost::asio::io_service&, bool, boost::optional<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::optional<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >)in ccs87Dq3.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

I really used the search function but I couldn't find any solution for my problem. What am I doing wrong?

Thanks a lot!

Sadeq
  • 7,795
  • 4
  • 34
  • 45
user1462040
  • 145
  • 2
  • 7

3 Answers3

9

After building cpp-netlib (>=0.9.3) there should 3 static libraries:

libcppnetlib-client-connections.a
libcppnetlib-server-parsers.a
libcppnetlib-uri.a

When building your http-client project, you should specify a library path for cpp-netlib (-L) and libraries to link (-l) against: cppnetlib-uri and libcppnetlib-client-connections.

Grigorii Chudnov
  • 3,046
  • 1
  • 25
  • 23
  • 2
    thanks to you the example is finally working now! in case someone has the same problem: here is the line that (after compiling the additional libs) finally did the trick for me: g++ test.cpp -o out -I/usr/local/Cellar/boost/1.53.0/include -L/usr/local/Cellar/boost/1.53.0/lib -lboost_system-mt -lboost_filesystem-mt -lboost_thread-mt -lcppnetlib-client-connections -lcppnetlib-uri -lcppnetlib-server-parsers -lssl -lcrypto – user1462040 Feb 24 '13 at 22:47
2

Here is what worked for me. You will need to modify certain parts to deal with different versions of boost, different install paths, and so on.

g++ -o demo \
    demo.cpp \
    -lcppnetlib-uri \
    -lcppnetlib-server-parsers \
    -lcppnetlib-client-connections \
    -lboost_thread-mt \
    -lboost_system-mt \
    -lssl \
    -lcrypto \
    -I/usr/local/include \
    -L/usr/local/lib

If you are writing server-side code then I imagine you will also need to include -lcppnetlib-server-parsers.

Alex Flint
  • 6,040
  • 8
  • 41
  • 80
0

In case someone is having the same issue with visual studio, provide the library input to the linker.

Project properties > Linker > input >

libcppnetlib-client-connectionsd.lib
libcppnetlib-urid.lib

for Debug configuration and

libcppnetlib-client-connections.lib
libcppnetlib-uri.lib

for Release configuration.

Specify the Library path here,

Project properties > Linker > general > Additional include directories

ProgramCpp
  • 1,280
  • 2
  • 15
  • 26