2

I am trying to link boost::asio using terminal (I'm also using a text editor).

What I tried

I did some researches on Internet (I didn't found nothing about my distro) - I found I must install that library by executing the following command on the terminal:

sudo pacman -S libboost-all-dev

This is the output I get:

error: the following package was not found: libboost-all-dev

Final question

How can I install and link correctly boost::asio with my .cpp file?

Notes:

  • I'm using Archlinux
orlow65
  • 23
  • 5
  • How can you link something with your text editor?! Maybe you mean "command line" or what? – ForceBru Dec 28 '15 at 13:25
  • @ForceBru correct. I edited my question – orlow65 Dec 28 '15 at 13:27
  • I know it's out of the direct question, but I suggest you to use CMake as project manager and handle Boost with it. Using CMake, you can even give compiler options to use Boost with Multithread support or link statically/dynamically your targets with it. Check this SO post: http://stackoverflow.com/a/3917033/2369389 – madduci Dec 28 '15 at 14:02
  • @orlow65 `-lboost_system` should be enough. Additionally, if you use threads to nicely scale `asio` then you also need `-lboost_thread`. – GreenScape Dec 28 '15 at 16:20
  • @GreenScape could you tell me the accurate name? If I add `-boost_system` as parameter i get errors... – orlow65 Dec 28 '15 at 16:22
  • @orlow65 those are parameters to `gcc` or `clang`. – GreenScape Dec 28 '15 at 16:22
  • @orlow65 to install package it seems that you need `pacman -Ss boost` – GreenScape Dec 28 '15 at 16:24
  • @GreenScape already installed. This is the command I tried: `g++ /home/hlw/Desktop/code.cpp -lboost-system` - but I still get dat error (not found):/ – orlow65 Dec 28 '15 at 16:27
  • @orlow65 So you should try `-lboost_system`, as I wrote before. There's underscore (`_`) between `boost` and `system`. – GreenScape Dec 28 '15 at 16:38
  • @GreenScape you solved my problem! A genius! Thank you! – orlow65 Dec 28 '15 at 16:40
  • @orlow65 you're welcome – GreenScape Dec 28 '15 at 17:02

2 Answers2

1

How to install boost in Arch Linux

You cannot link libraries inside your *.cpp files. You should enumerate required libraries using the -l option in the g++ command line.

g++ -lboos-asio -lboost-system myfile.cpp -o myapp
Community
  • 1
  • 1
brainstream
  • 451
  • 4
  • 17
1

To find a package in Arch Linux, do:

sudo pacman -Ss boost

This will list packages with the string boost. Or, you can look up on the package website: https://www.archlinux.org/packages/extra/x86_64/boost/

One thing you should understand about boost is that a majority of its modules are header-only; if the linker complains about undefined references then you would have to link the required files. To link boost-asio, you would do

g++ -lboost-system <source> <exe>
Poriferous
  • 1,566
  • 4
  • 20
  • 33
  • I get: `/usr/bin/ld: unable to find -lboost-asio \n collect2: error: ld returned 1 exit status` - but I just installed them – orlow65 Dec 28 '15 at 15:29
  • I checked my own system for boost-asio; there's no need to link it. But it's a good idea to link `boost-system`. In which case, boost-asio is a header-only module. – Poriferous Dec 28 '15 at 15:46
  • if I don't link boost-system I get errors! But when i try to compile with -lboost-system paramenter i get something like: `unable to find boost-system`! :( – orlow65 Dec 28 '15 at 15:49
  • thank you very much for your help! I solved my problem! – orlow65 Dec 28 '15 at 16:41
  • can you please share how you discovered to use -lboost-system? It doesn't seem to be in the boost docs, the g++ man page does not contain it either. And my system does not seem to recognise -lboost-system at all! – Anas Ayubi Apr 27 '18 at 09:21