0

I'm following this tutorial however it does not state which libaries I need to include in order to get boost to work,current options for links are:

-I/usr/include/opencv2 -I/usr/include/boost_1_55_0 -I/usr/include/boost_1_55_0/boost -O0 -g3 -Wall -c -fmessage-length=0

however this returns the following erro:

which states that it can't find asio, am I doing something wrong or was assio the wrong library to link to? Or is there any other way to find out. Note that this is my 2nd c++ project(through I have a lot of java experience) and first with the heavy use of libraries so details are somewhat required.

Removing boost/asio gave me the following errors:

make all 
Building target: DisplayImage
Invoking: GCC C++ Linker
g++ -L/usr/include/opencv2 -L/usr/include/boost_1_55_0/boost -L/usr/include/boost_1_55_0 -L/usr/include/opencv2 -L/usr/lib -o "DisplayImage"  ./src/Cap.o ./src/DisplayImage.o ./src/Filters.o ./src/sender.o   -lopencv_imgproc -lopencv_highgui -lopencv_core
./src/sender.o: In function `__static_initialization_and_destruction_0':
/usr/include/boost_1_55_0/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
/usr/include/boost_1_55_0/boost/system/error_code.hpp:223: undefined reference to `boost::system::generic_category()'
/usr/include/boost_1_55_0/boost/system/error_code.hpp:224: undefined reference to `boost::system::system_category()'
./src/sender.o: In function `error_code':
/usr/include/boost_1_55_0/boost/system/error_code.hpp:323: undefined reference to `boost::system::system_category()'
./src/sender.o: In function `boost::asio::error::get_system_category()':
/usr/include/boost_1_55_0/boost/asio/error.hpp:224: undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status
make: *** [DisplayImage] Error 1

Build Finished **

I use an ubuntu (x64) laptop if it matters.

Thijser
  • 2,625
  • 1
  • 36
  • 71
  • What is `-lboost/asio`? It seems meaningless, just remove this option. `Boost.Asio` is header-only, you don't need to link anything; however, it depends on `Boost.System`, so add `-lboost_system`. – Igor R. Mar 17 '14 at 17:40
  • Removing boost/asio gives me a large number of undefined references, however that might just be because it crashes before it reaches the part where things are undefined/? – Thijser Mar 17 '14 at 17:43
  • What undefined references? Please, copy the linker output. Did you link with Boost.System, as I mentioned in the above comment – Igor R. Mar 18 '14 at 09:00
  • Alright I added the requested info. – Thijser Mar 18 '14 at 10:09
  • @Did you read the previous comments? What is `-lboost.asio`? It doesn't make sense, remove it! Where's the list of "underfined references"? – Igor R. Mar 18 '14 at 10:41
  • Sorry wrong copy - paste here it is. – Thijser Mar 18 '14 at 13:05
  • Please, read the previous comments. You should link with `Boost.System` by adding `-lboost_system` option. – Igor R. Mar 18 '14 at 13:17
  • That gives me a /usr/bin/ld: cannot find -lboost_system error – Thijser Mar 18 '14 at 13:49
  • It means you either haven't built `Boost.System` or do not pass the appropriate path to the linker. Please refer to [Getting Started chapter](http://www.boost.org/doc/libs/1_55_0/more/getting_started/unix-variants.html). – Igor R. Mar 18 '14 at 14:05

2 Answers2

1

Most of boost is implemented in what's called "header-only" code. Through the generous use of C++ templates, there is no actual library code to which your code needs to link. However, there are, as you've seen some actual libraries as well. Generally, the help you seek is probably here: http://www.boost.org/doc/libs/1_55_0/more/getting_started/unix-variants.html#link-your-program-to-a-boost-library

Your particular program uses the timer and system libraries and so you can probably use this command line to link your program:

g++ timer.cpp -o timer -lboost_timer -lboost_system
Edward
  • 6,964
  • 2
  • 29
  • 55
  • In your link they make use of boost/stage which in my boost file does not exist. Any way around that and by the way I use ecliplse so I can't actually directly adres the command line. – Thijser Mar 19 '14 at 11:44
0

You can look at the bjam in boost/libs/asio/example/cpp03/tutorial/Jamfile.v2:

project
: requirements
    <library>/boost/system//boost_system
    <library>/boost/thread//boost_thread
    <define>BOOST_ALL_NO_LIB=1
    <threading>multi
    <os>SOLARIS:<library>socket
    <os>SOLARIS:<library>nsl
    <os>NT:<define>_WIN32_WINNT=0x0501
    <os>NT,<toolset>gcc:<library>ws2_32
    <os>NT,<toolset>gcc:<library>mswsock
    <os>NT,<toolset>gcc-cygwin:<define>__USE_W32_SOCKETS
    <os>HPUX,<toolset>gcc:<define>_XOPEN_SOURCE_EXTENDED
    <os>HPUX:<library>ipv6
;

You can see that they build all the tutorial steps with

-lboost_system -lboost_thread -DBOOST_ALL_NO_LIB=1

on linux

sehe
  • 374,641
  • 47
  • 450
  • 633