cannot find -lX11 - c++

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

Related

Wt Linking error on ubuntu

I installed WT:
sudo apt-get install witty witty-dbg witty-dev witty-doc
and now, when linking the Hello World example,
g++ -std=c++14 -o hello HelloW.cpp -I./src -L/usr/lib/lib -lwthttp -lwt
I get this error:
undefined reference to `Wt::Signals::Impl::Connection::~Connection()'
I wonder what I'm doing wrong. (Please look the odd link path I had to use).
EDIT:
I looked for one of the lib I'm trying to link:
find /usr/ -name "*wthttp*"
/usr/share/lintian/overrides/libwthttp38
/usr/share/lintian/overrides/libwthttp-dev
/usr/share/doc/libwthttp38
/usr/share/doc/libwthttp-dev
/usr/lib/libwthttp.so
/usr/lib/debug/usr/lib/libwthttp.so.3.3.4
/usr/lib/libwthttp.so.3.3.4
/usr/lib/libwthttp.so.38
/usr/lib/libwthttp.a

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?

Speed up RcppArmadillo: How to link to OpenBlas in an R package

I am working on an R package which uses RcppArmadillo. I am trying to take advantage of faster matrix multiplication found in OpenBLAS. In the documentation of the C++ armadillo library, it says if we have OpenBLAS on our machine then Armadillo would use OpenBLAS instead of BLAS. However, when I compile my R package, I get something like this:
g++ -m64 -std=c++11 -shared -L/usr/lib64/R/lib -Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -o PackageTest.so class1.o class2.o class3.o class4.o class5.o class6.o class7.o RcppExports.o class8.o class9.o class10.o -L/usr/lib64/R/lib -lRlapack -L/usr/lib64/R/lib -lRblas -lgfortran -lm -lquadmath -L/usr/lib64/R/lib -lR
So it is compiling with the -lRlapack and -lRblas options. How can I properly modify the Makevars and Makevars.win files to have RcppArmadillo compile the package with the option -lopenblas? My attempt to solve this problem was to modify the Makevars file in the following way:
PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
PKG_CXXFLAGS =-fopenmp -std=c++11 -lopenblas
PKG_CXX1XFLAGS = $(PKG_CXXFLAGS)
The package did compile with -lopenblas, but is this the best way to do it?
That is a problem with your RedHat installation which chose to rely on the internal LAPACK sources for R when installing R --- plus the fact that RcppArmadillo uses whatever R uses.
On my Debian/Ubuntu based machine, it happens differently. Ie for
R> library(Rcpp)
R> cppFunction("arma::mat foo(arma::mat x) { return x + x;} ", depends="RcppArmadillo", verbose=TRUE)
I get (inter alia)
g++ -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions \
-Wl,-z,relro -o sourceCpp_4.so file677111d81351.o \
-fopenmp -llapack -lblas -lgfortran -lm -lquadmath \
-L/usr/lib/R/lib -lR
and we see -llapack -lblas -lgfortran as expected.
Instructions for compiling R, OpenBLAS and linking R with OpenBLAS (GNU/Linux)
I believe your biggest problem is linking R to the OpenBLAS library. So the steps I write below can help you succeed in this link.
Compiling OpenBLAS
Initially download the R and OpenBLAS(Open Optimized BLAS Library) source codes in OpenBLAS. In the file directory, perform the following steps.
tar -zxvf OpenBLAS*
cd OpenBLAs*
make -j $nproc
sudo make install
export LD_LIBRARY_PATH=/opt/OpenBLAS/lib/
or
git clone https://github.com/xianyi/OpenBLAS.git
cd OpenBLAS*
make -j $nproc
sudo make install
export LD_LIBRARY_PATH=/opt/OpenBLAS/lib/
Note: This will make the compilation run faster using all the features of your CPU. To know the number of cores, do: nproc.
Compiling Armadillo C++ with OpenBLAS
For those who use C++ codes in R using the Rcpp library, setting up the Armadillo with the OpenBLAS library may be of some benefit.
tar -xvf armadillo*
cd armadillo*
./configure -DCMAKE_PREFIX_PATH=/opt/OpenBLAS/lib/
cmake . -DCMAKE_PREFIX_PATH=/opt/OpenBLAS/lib/
make -j $nproc
sudo make install
Note: Further details regarding the compilation of the Armadillo library can be found at https://gitlab.com/conradsnicta/armadillo-code.
Compiling R with OpenBLAS
After compiling OpenBLAS, download the R code. It is not necessary to compile R to make use of OpenBLAS, but compiling the language may bring some benefits that may be insignificant depending on what is being done in R. That way, download the source code of the language R.
Note: In my operating system, Arch Linux, OpenBLAS) was installed in the /opt directory. Search for the OpenBLASinstallation directory in your GNU/Linux distribution.
In the directory where the R was downloaded, do the following:
tar -zxvf R*
cd R-* && ./configure --enable-R-shlib --enable-threads=posix --with-blas="-lopenblas -L/opt/OpenBLAS/lib -I/opt/OpenBLAS/include -m64 -lpthread -lm"
make -j $nproc
sudo make install
Most likely the OpenBLAS library will be bound to R. To check, run in the R the sessionInfo() code. Something like the output below should appear:
Matrix products: default
BLAS/LAPACK: /opt/OpenBLAS/lib/libopenblas_haswellp-r0.3.6.dev.so
If linking does not occur, follow the steps outlined in the code below.
We need to link the R with the file libopenblas_*, created in the process of compiling the library OpenBLAS. In my case, the file is ibopenblas_haswellp-r0.2.20.so. Look for this in /opt/OpenBLAS/lib or in the directory where OpenBLAS was installed on your GNU/Linux system. Also look for the libRblas.so file directory found in the R language installation directory. In Arch, this directory is /usr/local/lib64/R/lib.
cd /usr/local/lib64/R/lib
mv libRblas.so libRblas.so.keep
ln -s /opt/OpenBLAS/lib/libopenblas_haswellp-r0.2.20.so libRblas.so
Start a section of language R and do sessionInfo(). You should note something like:
Matrix products: default
BLAS/LAPACK: /opt/OpenBLAS/lib/libopenblas_haswellp-r0.3.6.dev.so
To make use of multithreaded processing, do export OPENBLAS_NUM_THREADS=1 before starting a R section.
NOTE: For intel processors,sudo cpupower frequency-set -g performance, can boost performance. Read more at https://wiki.archlinux.org/index.php/CPU_frequency_scaling.

I installed libboost but can't link to it

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 )

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 :)