|
Boost Users : |
Subject: Re: [Boost-users] using asio.hpp - boost::system::generic_category()
From: Daniel Hofmann (daniel_at_[hidden])
Date: 2016-09-04 16:12:00
On September 4, 2016 11:12:06 AM GMT+02:00, Hermann Norpois <hnorpois_at_[hidden]> wrote:
>Hello,
>
>I just started with boost and it is obvious that I do not understand
>give
>my compiler (not mentioning code::blocks) the correct instructions.
>
>I installed boost_1_61_0 on Ubuntu 14.04 and followed the instruction.
>So I
>did (as root after sudo -i) in the directory of boost_1_61_0.
>I use g++4.9. It was the same with g++4.8.
>
>1) ./bootstrap.sh prefix=/usr/local
>
>2) ./b2 install
>
>So the libs are: /usr/local/lib
>
>The headers: /usr/include/boost
Are you sure those are not the system's boost headers? With the prefix set above I expect them to live at /usr/local/include/boost
Make sure you don't accidentally mix your custom boost installation's libraries with the system's boost headers.
Using gcc/clang use -I for setting include paths and -L for library paths.
>
>Actually I was interested in some stuff with asio. So I started with
>this code from the tutorial.
>http://www.boost.org/doc/libs/1_61_0/doc/html/boost_asio/tutorial/tutdaytime1/src.html
>
> g++ -Wall main.cpp -o zclient
>/tmp/ccxx7PrW.o: In Funktion
>`__static_initialization_and_destruction_0(int, int)':
>main.cpp:(.text+0x52e): Nicht definierter Verweis auf
>`boost::system::generic_category()'
>main.cpp:(.text+0x53a): Nicht definierter Verweis auf
>`boost::system::generic_category()'
>main.cpp:(.text+0x546): Nicht definierter Verweis auf
>`boost::system::system_category()'
>/tmp/ccxx7PrW.o: In Funktion `boost::system::error_code::error_code()':
>main.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17):
>Nicht definierter Verweis auf `boost::system::system_category()'
>/tmp/ccxx7PrW.o: In Funktion
>`boost::asio::error::get_system_category()':
>main.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x5):
>Nicht definierter Verweis auf `boost::system::system_category()'
>/tmp/ccxx7PrW.o: In Funktion
>`boost::asio::detail::posix_thread::~posix_thread()':
>main.cpp:(.text._ZN5boost4asio6detail12posix_threadD2Ev[_ZN5boost4asio6detail12posix_threadD5Ev]+0x26):
>Nicht definierter Verweis auf `pthread_detach'
>/tmp/ccxx7PrW.o: In Funktion
>`boost::asio::detail::posix_thread::join()':
>main.cpp:(.text._ZN5boost4asio6detail12posix_thread4joinEv[_ZN5boost4asio6detail12posix_thread4joinEv]+0x2b):
>Nicht definierter Verweis auf `pthread_join'
>/tmp/ccxx7PrW.o: In Funktion
>`boost::asio::detail::posix_thread::start_thread(boost::asio::detail::posix_thread::func_base*)':
>main.cpp:(.text._ZN5boost4asio6detail12posix_thread12start_threadEPNS2_9func_baseE[_ZN5boost4asio6detail12posix_thread12start_threadEPNS2_9func_baseE]+0x29):
>Nicht definierter Verweis auf `pthread_create'
>collect2: error: ld returned 1 exit status
Those are (localized) undefined reference linker errors. If you carefully read them, your linker is unable to find boost system symbols. Link with -lboost_system to fix this.
>
>I have to add that the simple programm in the starting guide worked
>properly
>http://www.boost.org/doc/libs/1_61_0/more/getting_started/unix-variants.html#link-your-program-to-a-boost-library
>
>via
>g++ -Wall main.cpp -o zu
>
>It worked in Code::Blocks as well (without any additional information).
>
>Even the second simple programm (same link) I managed to compile
>giving the full path:
>g++ -Wall main.cpp -o extractmail /usr/local/lib/libboost_regex.a
>
>At no time I had not to instruct the compiler about the headers. I was
>wondering. So it must have anything to do with the libs.
>
>Coming back to my asio- example. Do I need libs for it? I guess is has
>something to do with the expression -lboost_system. I used it without
>understanding it. But it did not help.
>
>Actually I would appreciate if was able to use Code::Blocks but I did
>not manage to give Code::Blocks the correct instructions. I
>
>found some hints, at least amounts of hints ... But it did not work at
>all.
>
>If somebody is able to explain it (for idiots) ... This would be great.
For gcc/clang
-I path/to/local/boost/headers
sets include paths to look for headers
-L path/to/local/boost/libraries
sets library paths to look for libraries
-lboost_system
links libboost_system to your program
(note: upper case i vs lower case L above)
I'm sure you'll find an equivalent in Code::Blocks.
>
>Thanks
>
>Hermann
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Boost-users mailing list
>Boost-users_at_[hidden]
>http://lists.boost.org/mailman/listinfo.cgi/boost-users
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net