I installed libboost but can't link to it - c++

I have installed libboost-dev through apt-get, and it's placed in /usr/lib.
/usr/lib$ ls | grep boost
libboost_filesystem.so.1.46.1
libboost_iostreams.so.1.46.1
libboost_serialization.so.1.46.1
libboost_system.so.1.46.1
libboost_thread.so.1.46.1
libboost_wserialization.so.1.46.1
But when I tried to compile a source that uses boost_thread I still got a error.
$ g++ tcp_echo.cpp -o tcp_echo -L/usr/lib -llibboost_thread
/usr/bin/ld: cannot find -lboost_thread
collect2: ld returned 1 exit status
$ g++ tcp_echo.cpp -o tcp_echo -L/usr/lib -lboost_thread
/usr/bin/ld: cannot find -lboost_thread
collect2: ld returned 1 exit status
What's the right way to install and link to libboost?

One thing I notice is that you do have no libboost_thread.so. You have
the versioned 1.46.1 file but usually libraries will create a symbolic
link to the versioned copy with the undecorated name. That might not
be it but it's one thing I noticed. (This is typically done by the
installer.) – Omaha
I think this is the point. It imply that I installed libboost the wrong way. In fact, I only installed libboost-dev:
sudo apt-get install libboost-dev
But what should I do is:
sudo apt-get install libboost-dev libboost1.46-doc libboost-date-time1.46-dev ibboost-filesystem1.46-dev libboost-graph1.46-dev libboost-iostreams1.46-dev libboost-math1.46-dev libboost-program-options1.46-dev libboost-python1.46-dev libboost-random1.46-dev libboost-regex1.46-dev libboost-serialization1.46-dev libboost-signals1.46-dev libboost-system1.46-dev libboost-test1.46-dev libboost-thread1.46-dev libboost-wave1.46-dev
(Or, in my particular case, install libboost-system1.46-dev libboost-thread1.46-dev at least)
And once you install them correctly, there should be .a and .so in /usr/lib.
/usr/lib$ ls | grep boost
libboost_date_time.a
libboost_date_time-mt.a
libboost_date_time-mt.so
libboost_date_time.so
libboost_date_time.so.1.46.1
libboost_filesystem.a
libboost_filesystem-mt.a
... and so on ...

In Ubuntu 16.04, the package is named: libboost-all-dev (not libboost-dev-all)

The comment box screwed up the quoting of this suggestion, so I'm posting it as an answer to get correct quoting.
It used to be, Ubuntu had the meta-package libboost-dev-all to install all of those. However, I can't seem to find it now. Here's a command line that might help:
sudo apt-get install `apt-cache search libboost | \
grep -- -dev | \
grep -v '[12]\.[0-9]' | \
awk '{ print $1; }'`
(Taken from https://github.com/imvu-open/istatd/ file install-boost-dev.sh )

Related

how to find location of missing library

I have installed the mysql connector for c++. I am writing a c++ cgi app. The cgi page has been compiling. I rebooted yesterday and it stopped compiling. g++ -o sales.cgi sales.cpp -lcgicc -lmysqlcppcon. Gives the following error. /usr/bin/ld cannot find -lmysqlcppcon
apt-get tells me I have the latest version of libmysqlcppconn7v5 and i have the latest version of libmyqlcppconn-dev. How do I find the library. I checked /usr/lib/ but I have no idea what I should be looking for.
Since you installed with apt-get, then you can use dpkg to determine which files were installed.
EXAMPLE (you would substitute "mysqlcppcon"):
dpkg -l|grep -i mysql
ii php-mysql 1:7.2+60ubuntu1 all MySQL module for PHP [default]
... <= Search for the exact package name (here, "php-mysql")
dpkg -L php-mysql
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/php-mysql
/usr/share/doc/php-mysql/copyright
/usr/share/doc/php-mysql/changelog.gz
<= List files installed to your system from that package
You can also use find
EXAMPLE:
find / -name "*mysqlcppcon*" -print 2> /dev/null
The *xxx* syntax let's you do a wildcard search; 2> /dev/null filters out irrelevant"noise" from your wildcard search, like "find: ‘/run/lvm’: Permission denied".
Thanks for all of the help. Huge typo on my side. I needed g++ -o sales.cgi sales.cpp -lcgicc -lmysqlcppconn

library missing cannot find -lbz2 in arch

while building statically an error
/usr/bin/ld: cannot find -lbz2
I am currently using arch linux. earlier I used ubuntu there I used
sudo apt-get install libbz2-dev
I am new to arch and dont know which library to install and how to find such libraries in future.
Maybe this info be useful:
archlinux:~$ ls /usr/lib/ | grep bz2
libbz2.so
libbz2.so.1
libbz2.so.1.0
libbz2.so.1.0.6
archlinux:~$ locate libbz2
/usr/lib/libbz2.so
/usr/lib/libbz2.so.1
/usr/lib/libbz2.so.1.0
/usr/lib/libbz2.so.1.0.6
/usr/lib32/libbz2.so
/usr/lib32/libbz2.so.1
/usr/lib32/libbz2.so.1.0
/usr/lib32/libbz2.so.1.0.6
I can see that libbz2.a file is missing how to get that?

cannot find -lX11

I am trying to compile a program, and the linking fails with the following message:
gcc -O2 -pipe -Wl,--export-dynamic tkAppInit.o -L/home/dimitriv/ns-allinone-2.35/tk8.5.10/unix -ltk8.5 \
-L/home/dimitriv/ns-allinone-2.35/tcl8.5.10/unix -ltcl8.5 -lX11 -ldl -lieee -lm -Wl,-rpath,/home/dimitriv/ns-allinone-2.35/lib -o wish
/usr/bin/ld: cannot find -lX11
collect2: error: ld returned 1 exit status
however, my $LD_LIBRARY_PATH contains the directory where X11 has been installed:
echo $LD_LIBRARY_PATH
/share/apps/cim/lib:/opt/ns2/otcl-1.13:/opt/ns2/lib:/home/dimitriv/local/lib:
and the libraries seem to be correctly installed.
ls /home/dimitriv/local/lib | grep X11
libX11.a
libX11.la
libX11.so
libX11.so.6
libX11.so.6.3.0
libX11-xcb.a
libX11-xcb.la
libX11-xcb.so
libX11-xcb.so.1
libX11-xcb.so.1.0.0
X11
Why can't make locate the libraries and do the linking?
The LD_LIBRARY_PATH contains paths to shared libraries which are used by the loader (ld program) to get the program to execute.
During compilation, include directories are used. During linking, object libraries are needed. The last one is the kind you are missing.
You might have to install a package to get the X11 development libraries. On Linux, the package is called libX11-devel. To install,
sudo yum install libX11-devel # for Redhat, Fedora, etc.
or
sudo apt-get install libX11-devel # for Ubuntu, etc.
as you can see in the compilation command itself:
gcc -O2 -pipe -Wl,--export-dynamic tkAppInit.o -L/home/dimitriv/ns-allinone-2.35/tk8.5.10/unix -ltk8.5 \
-L/home/dimitriv/ns-allinone-2.35/tcl8.5.10/unix -ltcl8.5 -lX11 -ldl -lieee -lm -Wl,-rpath,/home/dimitriv/ns-allinone-2.35/lib -o wish
the path
-L/home/dimitriv/local/lib
is not added.Add it in your make file and then check.
Solution:
Install the missing packages using
sudo apt-get install gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget

Linking error : undefined reference to `avahi_alternative_service_name'

in know i need to locate this symbol in library.. I am trying to compile avahi based test code to view services. But i am getting undefined reference toavahi_alternative_service_name'`.. I don't know which library contain this,I am running UBUNTU 12.04. I tried to install several packages but no success.. Any idea
Thanks..
I have following packages installed
dpkg --get-selections | grep avahi
avahi-autoipd install
avahi-daemon install
avahi-utils install
libavahi-cil-dev install
libavahi-client-dev install
libavahi-client3 install
libavahi-client3:i386 install
libavahi-common-data install
libavahi-common-data:i386 install
libavahi-common-dev install
libavahi-common3 install
libavahi-common3:i386 install
libavahi-core7 install
libavahi-glib-dev install
libavahi-glib1 install
libavahi-gobject0 install
libavahi-ui-dev install
libavahi-ui-gtk3-0 install
libavahi-ui0 install
libavahi1.0-cil install
command
gcc -fpermissive testAvahi.c -o testAvahi
Actually needed to locate libraries and then needed to pass them to linker, So follwing command did work for me
gcc -fpermissive testAvahi.c -o testAvahi -L/usr/lib/x86_64-linux-gnu/ -lavahi-client -lavahi-common
if you have a common folder where you place your c++ libraries you can check search for the function using the nm command
something like
cd /usr/lib
nm -AC * | grep avahi_alternative_service_name
The nm utility is available in binutils(sudo apt-get install binutils)

libboost-system linker errors when cross-compiling to x86

I'm trying to build a 32-bit application on Ubuntu 11.04 x64. I'm having some issues with the build because of linker errors with libboost. The build statement has -lboost_system in it, but when I try to build I get a bunch of these:
CommunicationModule.cpp:(.text+0x68c1): undefined reference to boost::system::generic_category()
CommunicationModule.cpp:(.text+0x68d7): undefined reference to boost::system::system_category()
Everything I've found on google says I need to link to the boost_system library. One place I found says to try linking to it directly, but when i do locate boost_system the result is empty. When I try doing a sudo apt-get install libboost-system-dev it tells me that it's already installed. I'm kind of at a loss here. The library is installed, but it's not being found by locate?
Can anyone tell me what I need to do to properly link to boost::system? I'm fairly new to linux and the complexities of compilers so any help here would be appreciated.
Update:
Here is the output of dpkg -L libboost-system1.42-dev:
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/libboost-system1.42-dev
/usr/share/doc/libboost-system1.42-dev/copyright
/usr/share/doc/libboost-system1.42-dev/NEWS.Debian.gz
/usr/share/doc/libboost-system1.42-dev/README.Debian.gz
/usr/lib
/usr/lib/libboost_system.a
/usr/lib/libboost_system-mt.so
/usr/lib/libboost_system-mt.a
/usr/lib/libboost_system.so
Is there a flag I can use to link to one of these directly? I tried using -L /usr/lib/libboost_system.so and -L /usr/lib/libboost_system-mt.so and neither of those fixed the issue. Same with just adding /usr/lib/libboost_system.a and /usr/lib/libboost_system-mt.a to the build statement.
Here is the compilation line:
g++ -m32 -Wl,-O1 -o UTNaoTool [.o files] -L/usr/lib32 -lqglviewer-qt4 -lqwt-qt4 -lboost_system -lboost_thread -lQtXml -lQtOpenGL -lQtGui -lQtNetwork -lQtCore -lGLU -lpthread
Update 2:
I downloaded boost 1.49 and built everything for 32-bit and that seemed to help. A lot of the errors went away, but now I still have these:
CommunicationModule.cpp:(.text+0x68c1): undefined reference to
boost::system::get_generic_category()
Note that the function is different. So all of my errors are regarding undefined references to get_system_category() and get_generic_category() now. I tried adding a -lboost_filesystem to the build command but that didn't fix this, and I made sure it was referencing the 32-bit library that I built when I built libboost_system.
Looking at my own installation, it seems libboost-system-dev does not install the libraries. Using dpkg to tell me what was installed bz libboost-system-dev I get:
$ dpkg -L libboost-system-dev
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/libboost-system-dev
/usr/share/doc/libboost-system-dev/copyright
/usr/share/doc/libboost-system-dev/changelog.gz
Poking around, I think you need to install libboost-system1.48.1 (or some other version).
sudo apt-get install libboost-system1.XX.Y
You can also search fo rthe libraries using the find command, for example, search under /usr for all files starting with libboost_system:
find /usr -name "libboost_system*"
Edit: Since you are cross-compiling from a 64 bit OS to a 32 bit one, you need 32 bit versions of the boost libraries. I would be tempted to set up a small 32 bit virtual machine to do this, rather than cross-compiling all the dependencies.
I had the same problem with boost_serialization here is what i found out after couple of googling..
first this library need to be compiled separately :
so after downloading the boost library ,extract it and execute sudo ./bootstrap.sh' then
sudo ./b2 --with-system
after this step you should be find a result when executing locate boost_system
then to link it manually I did:
both should work
g++ boostexample.cpp -o run /PATH/libboost_serialization.a
g++ boostexample.cpp -o run -L/PATH/ -lboost_serialization
well this is a little work around and I'm still looking for how to link the library properly
I hope this helped :)